Java decimal

作者: JaedenKil | 来源:发表于2019-11-19 15:57 被阅读0次

    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'.
    

    相关文章

      网友评论

        本文标题:Java decimal

        本文链接:https://www.haomeiwen.com/subject/rntgictx.html