royNiladri / js-big-decimal

Work with large numbers on the client side with high precision.
https://www.npmjs.com/package/js-big-decimal
MIT License
156 stars 28 forks source link

Division not giving enough precision #133

Closed thecaligarmo closed 2 months ago

thecaligarmo commented 7 months ago

Describe the bug Division is returning 0 for very small numbers

To Reproduce The following returns a value of 0, when it shouldn't:

var one = new bigDecimal('200000000000')
var two = new bigDecimal('17453700000.00000000')
var three = new bigDecimal('273484570903.25196072045472431920336519131248')
console.log(one.divide(two).divide(three))

Expected behavior This should give me a more precise decimal. In particular, it would be nice to have at least 4 (non-zero) values in the form of a.xyz E -1000000 or something like that. Or, allow some way to alter the precision when doing division with very small numbers.

Additional context No additional context.

Jsoto22 commented 5 months ago

@thecaligarmo the divide method takes a second parameter that specifies the maximum places of desired precision. The default value is 8, but can be set to any length.

You can use it as such :one.divide(two, 10000000).divide(three, 10000000)