Search code examples
javascriptnpmbignumber.js

Is there a way to get more precise result when dividing Big Number?


I need to operate on Big Numbers but I need the results to be precise, like below:

const BN = require('bn.js');
var a = 11060622312717714974
var b = 1570481433500000000000;
console.log(a/b); //0.0070428227146040415

When I use Big Number I get only 0, no precision:

var aBN = new BN('11060622312717714974');
var bBN = new BN('1570481433500000000000');
console.log(aBN.div(bBN).toString()); //0

Is it possible to get precise result with this library?


Solution

  • Not familiar with the library, but having a look at the README.md file, it says:

    Note: decimals are not supported in this library.

    So, according to that, the answer would be no.

    See https://github.com/indutny/bn.js/#usage.