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

toString() default base is not 10? #372

Closed 0x33dm closed 2 months ago

0x33dm commented 2 months ago

I see in the documentation that .toString() is supposed to be base 10, but when I test it on my application, the default isn't base 10.

Tested on google chrome with version 9.1.2

    console.log( BigNumber(10000000000000000000000).toString() ) //1e+22 
    console.log( BigNumber(10000000000000000000000).toString(10) ) // 10000000000000000000000
MikeMcl commented 2 months ago

1e+22 is the value in base 10, in exponential notation. The documentation at your link states:

If a base is not specified... then exponential notation is returned.

1e+22 means 1 x 10**22, which is the same as 10000000000000000000000.

0x33dm commented 2 months ago

1e+22 is the value in base 10, in exponential notation. The documentation at your link states:

If a base is not specified... then exponential notation is returned.

1e+22 means 1 x 10**22, which is the same as 10000000000000000000000.

I missed that. Thank you