MikeMcl / decimal.js

An arbitrary-precision Decimal type for JavaScript
http://mikemcl.github.io/decimal.js
MIT License
6.46k stars 475 forks source link

The result is "9.9999999999999999999" of 10/3*3 ? #54

Closed ghost closed 7 years ago

ghost commented 7 years ago

I tried the fllow code on https://npm.runkit.com/decimal.js

var decimalJs = require("decimal.js")

new decimalJs
.Decimal('10')
.dividedBy('3')
.mul('3')
.toString()

Expect: 10 Actual: "9.9999999999999999999"

MikeMcl commented 7 years ago

Please look at the result of Decimal('10').dividedBy('3'). Mathematically, that number multiplied by 3 is 9.9999999999999999999 not 10. This library does not store values as fractions.