0
How to handle a number which has digits more than 17 in javascript?
I have a number in json which is having digits more than 17. It does round off every time I try to show >17 digits. If 17 is the javascript limit. Please assist on how to handle this in code.
5 Answers
+ 6
The idea was to work with number stored as string, and convert only digit ( or few digits ) to integer so that you avoid problems of floating point numbers precision... It's relatively simple ( remember how you learn to calculate, on paper ) for integer, and with little more effort, if you need, you can handle floating point as well ;)
+ 3
@visph : I was wondering about custom handlers; if you followed the scheme of the current mantissa/exponent coding...but then:
https://modernweb.com/what-every-javascript-developer-should-know-about-floating-points/
...leads to BigDecimal, always using a tested library (preferred over writing your own) and arbitrary-precision floats:
https://github.com/dtrebbien/BigDecimal.js
+ 2
You mean float precision.
The maximum number of decimals is 17...
http://www.w3schools.com/js/js_numbers.asp
+ 2
You can code an handler for it... Look at http://www.2ality.com/2012/07/large-integers.html?m=1
( it's the first link google send me, and it seems to be a good point of start ^^ )
+ 2
@visph I got that :). And thanks, because other people can benefit from the tandem answers.