How do I print a double value without scientific notation using Java?

前端 未结 14 877
一整个雨季
一整个雨季 2020-11-21 11:52

I want to print a double value in Java without exponential form.

double dexp = 12345678;
System.out.println(\"dexp: \"+dexp);

It shows this

14条回答
  •  臣服心动
    2020-11-21 11:59

    You can try it with DecimalFormat. With this class you are very flexible in parsing your numbers.
    You can exactly set the pattern you want to use.
    In your case for example:

    double test = 12345678;
    DecimalFormat df = new DecimalFormat("#");
    df.setMaximumFractionDigits(0);
    System.out.println(df.format(test)); //12345678
    

提交回复
热议问题