MikeMcl / bignumber.js

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

The number is wrong #325

Closed NaturalZz closed 2 years ago

NaturalZz commented 2 years ago

let a = new BigNumber(273862376557801659) console.log(a.toNumber()) // 273862376557801660

shuckster commented 2 years ago

You need to pass strings to BigNumber:

BigNumber('273862376557801659')

Libraries like this exist to get around problems with the native number-type, which is the cause of your problem, so try to avoid using it and work with strings as much as possible.

MikeMcl commented 2 years ago

There is no JavaScript number with value 273862376557801659.

console.log(273862376557801659);    // '273862376557801660'