Supplying a float value of 37.35
I am getting a string of 37.3
Here is my code.
DecimalFormat format = new DecimalFormat(".0");
format.setRoundingMode(RoundingMode.HALF_UP);
return format.format(37.35f);
I would expect to receive a string of 37.4
. What am I doing wrong?
I think it may be due to passing a float in however I don't have a choice as to the type of variable I receive. Even if the actual representation of the float
was 37.3500221215051544
it should still be rounded up?
The whole point of formatting this value to a string is so I can pass it to BigDecimal
and have exact values such as 37.4
.