MikeMcl / bignumber.js

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

Can't be able to use both exponential notation and decimal places rounding #272

Closed ghsoares closed 4 years ago

ghsoares commented 4 years ago

Hello!

I'm trying to configure the BigNumber in that way that only displays two decimal places and display exponential at 5 digits, but as in the docs, if I use "toString()" without providing the base, the EXPONENTIAL_AT configuration is applied, if I use "toString(10)", the DECIMAL_PLACES configuration is applied, but I can't use both. I would like to be able to use both configurations, but I don't know if is possible. If it is, is a bit confusing on how is documented that.

Currently, I'm using this configuration:

BigNumber.config({ DECIMAL_PLACES: 2, EXPONENTIAL_AT: 5 });

MikeMcl commented 4 years ago

I'm not inclined to walk you through this - this kind of question would be better asked on a site like stackoverflow - but generally toFixed and toExponential are used to display to two decimal places, or use decimalPlaces(2) and then call toString. See also toFormat.

There are plenty of options, it is just a case of reading the docs and experimenting.