import java.text.DecimalFormat;
import java.util.Arrays;
import java.math.*;
public class MyClass {
public static void main(String args[]) {
DecimalFormat df = new DecimalFormat("#.###"); // can be changed to: #.##, #.####
df.setRoundingMode(RoundingMode.CEILING);
for (Number n : Arrays.asList(15, 751.123456, 0.87241, 98371.0984877, 0.01343, 0.2)) {
Double d = n.doubleValue();
System.out.println(df.format(d));
}
}
}
/*
run:
15
751.124
0.873
98371.099
0.014
0.2
*/