double roundOff = Math.round(a * 100.0) / 100.0;
// Or
double roundOff = (double) Math.round(a * 100) / 100;
// both have the same output.
class round{
public static void main(String args[]){
double a = 123.13698;
double roundOff = Math.round(a*100)/100;
System.out.println(roundOff);
}
}
int a = (int) Math.round(doubleVar);
// calling the function round
round(200.3456, 2);
// Include this function in your class
public static double round(double value, int places) {
if (places < 0) throw new IllegalArgumentException();
BigDecimal bd = BigDecimal.valueOf(value);
bd = bd.setScale(places, RoundingMode.HALF_UP);
return bd.doubleValue();
}
class round{
public static void main(String args[]){
double a = 123.13698;
double roundOff = Math.round(a*100)/100; //put attention to the parenthesis.
System.out.println(roundOff);
}
}