Rounding issue with ROUND_HALF_UP
nathany opened this issue · 1 comments
nathany commented
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 commented
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. :-)