Java Rounding off to 2 decimal places

The following is a code fragment to round off a double value to two decimal places in Java.

double originalValue = 11.2678;
               
double roundedValue = Math.rint(originalValue*100)/100;
               
System.out.println("roundedValue -> "+roundedValue);

Search