localized-digits
TL;DR
You must use String.format(Locale.US, "%d", 1)
to produce machine-readable
expression of digits in string, otherwise it may produce non-ascii localized
characters in some locales.
What is this?
This single activity application shows the result of
String.format("%d", 1234567890)
in available locales on your device.
That's all, but you can try it on your device if you want.
Background
Sometimes you face to unexpected behavior on popular standard functions.
String result = String.format("%d", 1);
Most people expects result
is 1
, but in some cases this is not true.
The result depends on current locale you use.
This is expected, documented behavior of java.util.Formatter
.
Each digit expression is generated as offset from zero-digit character
on current locale (for example 0
in en, ٠
in ar, and ၀
in my)
by using java.text.DecimalFormatSymbols#getZeroDigit()
.