How to display Persian(Farsi) numbers in views
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);