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

Least significant digit is lost #10

Closed
omidkrad opened this issue Nov 8, 2019 · 1 comment
Closed

Least significant digit is lost #10

omidkrad opened this issue Nov 8, 2019 · 1 comment

Comments

@omidkrad
Copy link

omidkrad commented Nov 8, 2019

Hi, I found a bug in my application and I could debug it down to what I'm breaking down below:

import Decimal from 'decimal.js-light';

let number = 1.01322716;
let result1 = new Decimal(number).mul(1).toNumber();  // => 1.0132271
let result2 = new Decimal(number).plus(0).toNumber(); // => 1.0132271

let a = number === result1;  // => false
let b = number === result2;  // => false
let c = result1 === result2; // => true

The least significant digit is lost. Do you know why this is happening and how to avoid it?

Thanks!

@omidkrad
Copy link
Author

omidkrad commented Nov 8, 2019

OK, never mind. I figured some configuration that set precision a lower number was leaking in the app. Removing that fixed the issue. BTW, thanks for this excellent library.

@omidkrad omidkrad closed this as completed Nov 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant