0

I have the String which i need to convert the Long. I using the Number and parseFloat digit value is getting changed 8807867939188684786 -->> 8807867939188685000

I have to convert the INC8807867939188684786 to 8807867939188684786 as long or Number

"INC8807867939188684786".slice(3)
output :  "8807867939188684786"

1st Try

Number("INC8807867939188684786".slice(3))
 Output : 8807867939188685000

2nd try

 parseFloat("INC8807867939188684786".slice(3))
14:39:36.420 8807867939188685000
Prabhat Yadav
  • 1,181
  • 6
  • 18
  • 29
  • welcome to [64 bit floating point format](https://en.wikipedia.org/wiki/Double-precision_floating-point_format). – Nina Scholz Jan 12 '18 at 09:22
  • 1
    IEEE-754 double-precision (64 bit) gives you only 53 bits mantissa. Consider [additional libraries](https://github.com/broofa/node-int64) – Aleksey Solovey Jan 12 '18 at 09:26
  • from the font end (javascript/angular ) we can not get exactly save digit ? thanks Nina and @\aleksey for useful knowledge update. – Prabhat Yadav Jan 12 '18 at 09:32

2 Answers2

0

As I understood biggest integer that can be precisely stored in JavaScript is 2^53 (9007199254740992). And the only way to avoid it is using libraries like https://github.com/MikeMcl/big.js

Source

Yarik
  • 742
  • 8
  • 13
0

JavaScript number store limited number of digits (16). Generaly you can solve this problem into two ways:

  1. Using strings to store your numbers (will work if you don't need to do calculations with your large numbers)

  2. Use one of Big Number library for javascript. You can try BigNumbers it is fresh, well documented and activelly supported library

alexey28
  • 5,170
  • 1
  • 20
  • 25