This is a migrated thread and some comments may be shown as answers.

Formatting numbers in E notation with exponent > 20 or <-20 fails

1 Answer 169 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Luciano
Top achievements
Rank 1
Luciano asked on 20 Jun 2014, 10:12 AM
Hello.

I have stumbled upon a problem when trying to format numbers which are in E notation with very large exponents.

Please look at the example below where the first number is correctly formatted while the second one produces an exception.

kendo.toString(5e15, "#,0.00")
"5,000,000,000,000,000.00"
kendo.toString(5e25, "#,0.00")
RangeError: toFixed() digits argument must be between 0 and 20

Same behavior can be observed for negative exponents:
kendo.toString(5e-20, "#,0.00")
"0.00"
kendo.toString(5e-21, "#,0.00")
RangeError: toFixed() digits argument must be between 0 and 20


I believe the problem is in your round function where it is returning "value.toFixed(precision);" The native Number.toFixed function appears to be limited to a maximum of 20 digits which makes formatting of above numbers break.

Could you please implement a fix which removes this limitation?


Thanks.


1 Answer, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 24 Jun 2014, 08:29 AM
Hi Luciano,

As this is a well known limitation of the Number.prototype.toFixed() implementation there is nothing that we can do to in order to work around it. Currently the round method relies on toFixed() to adjust the precision of the numbers. 

If you think that the current implementation needs improvement, please check our UserVoice section, where you can post this as a suggestion for improvement and if it gets popular a change will be implemented. 

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
General Discussions
Asked by
Luciano
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Share this question
or