I have the following code:
int color = 0;
int number = 0;
// ...
s = String.format("%dproduct%d", color, number);
This works fine on my computer and on my Android device. I get strings like 0product0
etc.
BUT in production, on users' Android devices, I get strings like:
٠product٠
٠product١
٠product٢
٠product٣
٠product٤
Does String.format() not work OK when starting with a number?
The strings you get are "correct" for an Arabic Locale, as e.g. the UTF-8 dual-byte value d9 a0
(as posted by Andy) encodes the Unicode code point U+0660
, being the ARABIC-INDIC DIGIT ZERO
.
As the rest of your output isn't locale-dependent, you probably want the numbers shown in US Locale as well, as proposed by Hitesh Sarsava:
String s = String.format(Locale.US, "%dproduct%d", color, number);
use format like this :
String s = String.format(Locale.getDefault(), "%dproduct%d", color, number);
or use as per your requirement like this :
String s = String.format(Locale.US, "%dproduct%d", color, number);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With