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

Precision on result #96

Closed
nicolas-eveno opened this issue Aug 20, 2018 · 4 comments
Closed

Precision on result #96

nicolas-eveno opened this issue Aug 20, 2018 · 4 comments

Comments

@nicolas-eveno
Copy link

I don't know if it's a bug but I don't understand why exp4j gives this result.
249 * 0.595 = 249.305
BigDecimal.valueOf(419).multiply(BigDecimal.valueOf(0.595));
This give 249.305 too. I wait same with exp4j

Now with exp4j:
new ExpressionBuilder(regle).variable("d").variables("d").build().setVariable("d", 419).evaluate();
I obtain 249.30499999999998.

Do you know what is wrong?

@RobertZenz
Copy link

Yeah, read up about floating-point precision. In short, float and double is, mostly, an approximation of values.

@nicolas-eveno
Copy link
Author

Yes I think too. It's bad me. Using Double is not a good thing in my app. Do you know an alternative with this lib or other?

@RobertZenz
Copy link

There is EvalEx which is similar and uses BigDecimals...and before you ask look at EvalEx#114.

@nicolas-eveno
Copy link
Author

Thank you. I try it.

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

3 participants