round up to one decimal place java code example
Example 1: print up to 2 decimal in java
System.out.printf("%.2f", value);
Example 2: java round double to 2 decimal places
import java.math.RoundingMode;
import java.text.DecimalFormat;
public class DecimalExample {
private static DecimalFormat df = new DecimalFormat("0.00");
public static void main(String[] args) {
double input = 1205.6358;
System.out.println("salary : " + input);
System.out.println("salary : " + df.format(input));
df.setRoundingMode(RoundingMode.DOWN);
System.out.println("salary : " + df.format(input));
df.setRoundingMode(RoundingMode.UP);
System.out.println("salary : " + df.format(input));
}
}