Convert scientific notation to decimal notation

后端 未结 3 1848
情歌与酒
情歌与酒 2021-01-21 02:10

There is a similar question on SO which suggests using NumberFormat which is what I have done.

I am using the parse() method of NumberFormat.

public sta         


        
3条回答
  •  南方客
    南方客 (楼主)
    2021-01-21 02:55

    Memorize the String.format syntax so you can convert your doubles and BigDecimals to strings of whatever precision without e notation:

    This java code:

    double dennis = 0.00000008880000d;
    System.out.println(dennis);
    System.out.println(String.format("%.7f", dennis));
    System.out.println(String.format("%.9f", new BigDecimal(dennis)));
    System.out.println(String.format("%.19f", new BigDecimal(dennis)));
    

    Prints:

    8.88E-8
    0.0000001
    0.000000089
    0.0000000888000000000
    

提交回复
热议问题