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

divide error when i use 1e21 over number use #37

Closed riverfrot closed 4 years ago

riverfrot commented 4 years ago

Describe the bug A clear and concise description of what the bug is.

An error occurs when dividing with a number greater than 1e21.

To Reproduce Steps to reproduce the behavior, preferably with sample code.

const data = 1e21 multiplier = new bigDecimal(Math.pow(10, 18)); console.log(data / multiplier.value) let divideAsset = bigDecimal.divide(received.toString(), multiplier.value, 18) console.log('divideAsset') console.log(divideAsset) ===> 10.000000000000000000(error)

Expected behavior A clear and concise description of what you expected to happen. ===> 1000.0000000000000000(Normal case)

Additional context Add any other context about the problem here.

royNiladri commented 4 years ago

In the example code, i do not see you initialising receivedvalue. Moreover, you are not using it as expected. Your data is not a string or bigdecimal.

royNiladri commented 4 years ago

Here is a working example:

var big = require("js-big-decimal")
a = new big('1e21');
b = new big('1e18')
console.log(a)
console.log(b)
console.log(a.divide(b))

image