Given the example code:
String format = "{0,number}"; // <- What do I put here?
double value = Math.PI * 1e-10;
System.out.println(value);
System.out.println(new MessageFormat(format, Locale.US).format(new Object[]{value}));
System.out.println(new MessageFormat(format, Locale.FRANCE).format(new Object[]{value}));
What do I use as the format string such that I get full precision output of any double value and that the output is localized? For example, the output of the current code is:
3.1415926535897934E-10
0
0
String.valueOf(double)
correctly prints the full precision, but it isn't a message format and it is not localized. The message format decides the value is too small to bother with. For large numbers the results are even worse! MessageFormat
prints 16 significant digits and then appends a bunch of zeros that do not accurately reflect the value stored in the double. E.g. with pi * 1e100
I get:
3.141592653589793E100
31,415,926,535,897,930,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000
31 415 926 535 897 930 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000