You can use setRoundingMode() method to get n digit decimal values.
To write a solution for this question, you have to import 3 libraries.
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Arrays;
After importing these libraries, write the statements given below.
public static void main(String[] args) {
DecimalFormat df = new DecimalFormat("#.##");
df.setRoundingMode(RoundingMode.CEILING);
for (Number n : Arrays.asList(15.00000, 13.23456)) {
Double d = n.doubleValue();
System.out.println(df.format(d));
}
}
Output will be:
15
13.24