How to round to 2 decimal places in Java?

To round to 2 decimal places in Java, do this: Math.round(number * 100.0) / 100.0.

Here's how you do it:

double number = 123.456789;
double rounded = Math.round(number * 100.0) / 100.0;

System.out.println(rounded); // 123.46