MikeMcl / bignumber.js

A JavaScript library for arbitrary-precision decimal and non-decimal arithmetic
http://mikemcl.github.io/bignumber.js
MIT License
6.64k stars 741 forks source link

Last digit of number is round off when number of digits length is 20 #292

Closed Soni-Goyal closed 3 years ago

Soni-Goyal commented 3 years ago

My data is coming from third party API in node and this data contains an id of number type whose number of digits are 20(69673776659654677224). They don't provide any string format.

After trying this library, my last digit is still truncated when i try to do new BigNumber(id).toFixed() Hence doesn't provide correct id to me

Can someone please help how to handle it ?

MikeMcl commented 3 years ago

It's not an issue with this library.

Number(69673776659654677224)    // 69673776659654680000

Basically, you need to put quotes around the values before you parse them.

See, for example, parse json with large numbers or convert an extra large number to string in json etc.

Soni-Goyal commented 3 years ago

Thanks its working using JSON.stringify replace method