Reputation: 83
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?
Upvotes: 8
Views: 654
Reputation: 7290
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);
Upvotes: 4
Reputation: 680
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);
Upvotes: 2