Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiplication by 100 returning unexpected results #3199

Open
rmclaughlin-nelnet opened this issue May 2, 2024 · 1 comment
Open

Multiplication by 100 returning unexpected results #3199

rmclaughlin-nelnet opened this issue May 2, 2024 · 1 comment
Labels

Comments

@rmclaughlin-nelnet
Copy link

rmclaughlin-nelnet commented May 2, 2024

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

@josdejong
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants