Java

Java decimal

2019-11-19  本文已影响0人  JaedenKil

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'.
上一篇 下一篇

猜你喜欢

热点阅读