Say, "1920 / 1080" is 1.777777777..., want the calculation to output '1.778'.
import java.text.DecimalFormat;
public class DecimalTest {
private static DecimalFormat df = new DecimalFormat("0.000");
public static void main(String[] args) {
show((double) 1920 / 1080);
}
@SuppressWarnings("SameParameterValue")
private static void show(Number number) {
System.out.println("It is: '" + df.format(number) + "'.");
}
}
It is: '1.778'.
网友评论