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

Rounding issue with ROUND_HALF_UP #11

Open
nathany opened this issue Mar 15, 2013 · 1 comment
Open

Rounding issue with ROUND_HALF_UP #11

nathany opened this issue Mar 15, 2013 · 1 comment

Comments

@nathany
Copy link

nathany commented Mar 15, 2013

Based on the Java documentation, my expectation is that these two lines would result in the same value:

new BigDecimal(0.615000001).setScale(2, BigDecimal.ROUND_HALF_UP).toString() // => "0.62"
new BigDecimal(0.615).setScale(2, BigDecimal.ROUND_HALF_UP).toString() // => "0.61"
@nathany
Copy link
Author

nathany commented Mar 15, 2013

Apparently I should be passing in a string, otherwise it's already a floating point number.

new BigDecimal("0.615").setScale(2, BigDecimal.ROUND_HALF_UP).toString() // => "0.62"

It might help to stress this in the README for people like me. :-)

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