Multiplication by 100 returning unexpected results
The issues section is used only for bug reports. Please use the Discussions section to ask questions and share ideas and suggestions.
Describe the bug I am trying to convert a decimal representation of a percent to a integer. So I am multiplying the number by 100, but the result is not something I expected.
To Reproduce
const math = require('mathjs'); math.chain(0.0749).multiply(100).done(); 7.489999999999999
Any help in fixing this? I would round, but I don't always know how many decimals I need. I am currently using v 12.4.1
This is the most asked question. It is a floating point round-off error. You can either use format to hide the round-off error in the output, or use BigNumber to work with a higher precision.
See docs: https://mathjs.org/docs/datatypes/numbers.html#roundoff-errors
Closing as duplicate of #2811.