How can I print floating point values ​​without the mantissa / exponent format?

I am trying to print a double value. It prints in matissa and exponent format, which I don't want. For example, my program prints 1.234567E6for the value 1243567. How can I print 1234657?

+5
source share
4 answers

You can take a look at the NumberFormat and DecimalFormat class .

+2
source
BigDecimal.valueOf(double).toPlainString();
+3
source

, : . , , .

. "d" "f" . " ", , f , . , .

Double Value 12345678 :

Double d = Double.parseDouble("12345678");
String r1 = String.format("%f",d);        // 12345678.000000
String r2 = String.format("%10f",d);      // 12345678.000000
String r3 = String.format("%5.2f",d);     // 12345678.00
String r4 = String.format("%5.0f",d);     // 12345678
String r5 = String.format("%,f",d);       // 12,345,678.000000
String r6 = String.format("%,5.0f",d);    // 12,345,678
String r7 = String.format("%d",d);        // throws an exception!

, , 'd' Double.

0
source

All Articles