EN
Java - round double to 2 decimal places
5 points
Quick solution:
xxxxxxxxxx
1
public class RoundExample {
2
3
public static double roundTo2thDecimalPlace(double value) {
4
return Math.round(value * 100.0) / 100.0;
5
}
6
7
public static void main(String[] args) {
8
System.out.println(roundTo2thDecimalPlace(1.23400000001)); // 1.23
9
System.out.println(roundTo2thDecimalPlace(1.234)); // 1.23
10
System.out.println(roundTo2thDecimalPlace(1.2)); // 1.2
11
}
12
}