Java, double too large, to avoid showing how to use scientific notation

Articles published in the personal blog priority, subsequent updates may forget synchronized to CSDN.
Personal blog this article Location: https://www.xdx97.com/article?bamId=664138763500257280

1, as far as possible using BigDecimal to replace, double. Although BigDecimal operate some trouble, but at the show, and indeed have an advantage in convenience precision.

2, through experiments, I have come to when the data is greater than 1000W, double scientific notation will be used to show, given the following two ways to solve this problem.

    public static void main(String[] args) {
        double j = 10000000.1;
        System.out.println(j);

        // 方法一
        NumberFormat nf = NumberFormat.getInstance();
        nf.setGroupingUsed(false);
        System.out.println(nf.format(j));
        
        //方法二
        System.out.println(new BigDecimal(j + "").toString());
    }
Published 302 original articles · won praise 127 · views 520 000 +

Guess you like

Origin blog.csdn.net/Tomwildboar/article/details/103876558