I have a number with value
0.947
Now, I use DecimalFormat API of java.text with the following pattern and RoundingMode-
double numberToFormat = 0.947;
DecimalFormat restrictTo1DecimalPlace = new DecimalFormat("0.0%");
restrictTo1DecimalPlace.setRoundingMode(RoundingMode.DOWN);
String formattedString = restrictTo2DecimalPlace.format(numberToFormat);
Now, I was expecting the value of formattedString
to be 94.7% but its 94.6%
.
I know the value has been set to RoundMode.Down but then why does value of following are not rounded down -
- 0.9471 -> 94.7%
- 0.9447 -> 94.4%