I am wondering why running the following:
as "java Test" returns -0.01 and not 0.00?
And scale of 1 will doubtlessly round to 0.0. I guess I wasn't clear that I'm doing financial calculations and
I'm trying to round to pennies.
−2.1349 rounded to hundredths is −2.13
−2.1350 rounded to hundredths is −2.14
I would have also rounded the latter to -2.13, since -2.13 is numerically greater than -2.1350. Anyway, I was trying to remember (see ROUND_HALF_UP JavaDoc) for the following excerpts:
Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up. Note that this is the rounding mode that most of us were taught in grade school.
back to when I learned to round negative numbers, and I'm pretty sure when I was in grade school, I learned to round negative numbers the way the above scaleAndRound() static method works and not the way ROUND_HALF_UP works. I must admit that I feel I was misled by the documentation, though I am impressed by the variety of BigDecimal rounding methods available, and surprised that there is nothing out of the box which matches what I was looking for, which I feel would be a very common rounding usage. I think my problem is solved. Thank you very much.
[ April 04, 2007: Message edited by: Jim Harding ]