Does anyone know why the numbers 0.001 to 0.009 are rendered to a String with a trailing 0 but other numbers do not. e.g. numbers 0.01 to 0.09 do not.
System.out.println(Locale.getDefault());
for (int i = 0; i <= 20; i++)
System.out.println(i / 1e3);
prints
en_GB
0.0
0.0010
0.0020
0.0030
0.0040
0.0050
0.0060
0.0070
0.0080
0.0090
0.01
0.011
0.012
0.013
0.014
0.015
0.016
0.017
0.018
0.019
0.02
EDIT The code for DecimalFormat doesn't appear to be locale dependant. If I run
for (Locale l : Locale.getAvailableLocales()) {
Locale.setDefault(l);
System.out.println(l + " " + 1 / 1e3);
}
on Java 6 update 26 on Ubuntu 11.04 I get
ja_JP 0.0010
es_PE 0.0010
en 0.0010
... many locales with the same result ...
sv_SE 0.0010
da_DK 0.0010
es_HN 0.0010
on Java 7 on same system I get
ms_MY 0.001
ar_QA 0.001
is_IS 0.001
... many locales with the same result ...
el_CY 0.001
hu 0.001
fr_FR 0.001
Locale loc = Locale.forLanguageTag("hi"); Locale.setDefault(loc);
. EDIT: I also don't get it for en_US. EDIT 2: As a matter of fact, I don't get trailing zeroes for any locale. – Burny