Convert Double to String without precision loss in javascript
Posted
by
holger
on Stack Overflow
See other posts from Stack Overflow
or by holger
Published on 2012-12-07T16:29:53Z
Indexed on
2012/12/07
17:06 UTC
Read the original article
Hit count: 385
JavaScript
I would like to convert a floating point variable to a string without losing any precision.
I.e. I would like the string to have the same information as my floating point variable contains, since I use the output for further processing (even if it means that the string will be very long and readable).
To put this more clearly, I would like to have functions for cyclic conversion
var dA = 323423.23423423e4;
var sA = toString(dA);
var dnA = toDouble(sA);
and I would like dnA and dA to be equal
Thanks
PS: Sources on the internet usually talk about how to round strings but I have not found information on exact representation. Also I am not interested in Arbitrary Precision calculations, I just need double precision floating point arithmetic.
© Stack Overflow or respective owner