First declare an object of class DecimalFormat . Note that the argument inside DecimalFormat is #.00 , which means exactly 2 decimal rounding points.
private static DecimalFormat df2 = new DecimalFormat("#.00");
Now apply the format to your double value:
double input = 32.123456; System.out.println("double : " + df2.format(input));
Note in the case of double input = 32.1;
Then the output will be 32.10 , etc.
Dibyendu Mitra Roy Jun 05 '17 at 6:35 2017-06-05 06:35
source share