I am loading a string which contains some number (all in Persian) into an android TextView. Everything was fine until I changed my custom font, numbers of text shown as English number.
Expected : ۱۲۳۴
Received : 1234
I know that my new font support Persian number. When I change the number locale using code below the number shown correctly.
NumberFormat numberFormat = NumberFormat.getInstance(new Locale("fa", "IR"));
String newNumber = numberFormat.format(number);
The problem is I have a string and it's hard to find the numeric part and change it. also my previous font works fine and I can't understand what's the problem with this font.
Any Idea how to globally solve this problem for all textview, or at least for a string?
Try to use this method:
private String setPersianNumbers(String str) {
return str
.replace("0", "۰")
.replace("1", "۱")
.replace("2", "۲")
.replace("3", "۳")
.replace("4", "۴")
.replace("5", "۵")
.replace("6", "۶")
.replace("7", "۷")
.replace("8", "۸")
.replace("9", "۹");
}
You can use this
String NumberString = String.format("%d", NumberInteger);
123 will become ١٢٣
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