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

Calculation error #361

Closed contractsolidity closed 7 months ago

contractsolidity commented 8 months ago

console.log(new BigNumber(2.5775384794659629771166494749061e+26).minus('2.5775384794659629771166494749061e+26').toString())

result 2288335052.50939

shuckster commented 8 months ago
console.log(
  new BigNumber("2.5775384794659629771166494749061e+26")
    .minus("2.5775384794659629771166494749061e+26")
    .toString()
);
// "0"

const x = 2.5775384794659629771166494749061e26;
const y = 2.5775384794659629771166494749062e26;
//                                        ^
console.log(x === y);
// true

You need to use strings, not numbers.