I used the class BigDecimal and used the field ROUNDHALFUP in order to round up a number, but it didn't round up.
More specifically, the number was the double obtained by dividing 1942 by 40. If you divide 1942 by 40 on paper, you get 48.55 exactly, so I figured that using ROUNDHALFUP would give me 48.6 but instead I got 48.5.
I thought about it a bit, and I assume that dividing 1942.0 by 40.0 would give a double very close to 48.55, but not exactly because the numbers are all binary instead of base 10. Also, although 48.5 would be exact, 48.6 would not be exact.
What I used to do to round to the nearest tenth was like this:
double a;
double b;
double d = 10.0 * a/b + 0.5;
int result = (int) d;
// then change result into a
string, stick a period in just before the last digit on the right, and add a zero on the left if necessary
You know what I mean, I think. But that takes up a lot of space in a program. Using BigDecimal saved space, but I got a result I did not want. There must be some simple way to round accurately to the nearest tenth. Anyone know what it is?