I want to display Persian(Farsi) numbers on views. For example I calculated a date and converted it to Jalali calendar but how can I display it by Persian numbers?
Persian numbering rules Digits from zero to nine are specific words, namely sefr (صفر) [0], yek (یک) [1], do (دو) [2], se (سه) [3], chahâr (چهار) [4], panj (پنج) [5], shesh (شش) [6], haft (هفت) [7], hasht (هشت) [8], and noh (نه) [9].
Another way to show numbers with Persian font is the use of following Helper Class:
public class FormatHelper { private static String[] persianNumbers = new String[]{ "۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹" }; public static String toPersianNumber(String text) { if (text.length() == 0) { return ""; } String out = ""; int length = text.length(); for (int i = 0; i < length; i++) { char c = text.charAt(i); if ('0' <= c && c <= '9') { int number = Integer.parseInt(String.valueOf(c)); out += persianNumbers[number]; } else if (c == '٫') { out += '،'; } else { out += c; } return out; } }
Save this class as UTF8 format and use it like the following code
FormatHelper.toPersianNumber(numberString);
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