0.1 + 0.2 = 0.30000000000000004 ? #2811
-
Node.js v16.17.0.
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
This is the most asked question. This is a round-off error. Docs: https://mathjs.org/docs/datatypes/numbers.html#roundoff-errors |
Beta Was this translation helpful? Give feedback.
-
@josdejong should we put a question in Discussions with an accepted answer for this (would be nice if we could "pin" FAQs there), and/or put something in the issue template (is there one now?) that mentions a list of common questions not to post? Seems like this comes up almost every other week and it's a waste of time. |
Beta Was this translation helpful? Give feedback.
-
👍 yes will do, I forgot about this not being in the Discussions section. |
Beta Was this translation helpful? Give feedback.
-
I always use a=0.1,b=0.2;
print(math.evaluate('0.1+0.2'))
// 0.30000000000000004
print(math.simplify('0.1+0.2'))
// 3/10
print(math.evaluate(math.simplify('0.1+0.2')))
// 0.3 |
Beta Was this translation helpful? Give feedback.
This is the most asked question. This is a round-off error.
Docs: https://mathjs.org/docs/datatypes/numbers.html#roundoff-errors
Similar questions: https://github.com/josdejong/mathjs/issues?q=is%3Aissue+round-off+is%3Aclosed