Reputation: 15158
I'm trying to display numbers in fa_IR
locale.
I'm using this code:
NumberFormat.getNumberInstance(new Locale("fa","IR")).format(myNum);
But this prints English (en_US
) numbers.
How can I display a number in a specific locale in Java?
Example:
For example if myNum
be 12
the output should be ۱۲
Edit:
It seems java.text.NumberFormat
doesn't support fa_IR
locale (?).
Using com.ibm.icu.text.NumberFormat
instead, fixes the problem!
Upvotes: 4
Views: 3349
Reputation: 3665
As you know Oracle (or it's better to say Java Programming language ) does not support Persian directly, in order to have a Persian( or Arabic ) NumberFormat you can use the below codes:
NumberFormat numberFormat = NumberFormat.getNumberInstance(new Locale.Builder().setLanguageTag("ar-SA-u-nu-arab").build());
System.out.println(numberFormat.format(1234567890));
The output will be like this:
۱،۲۳۴،۵۶۷،۸۹۰
as you can see by using this kind of code your output number not only will be in Persian style but also its each three numbers will be grouped and separated by a "," character.
Upvotes: 7
Reputation: 3265
Try this code:
NumberFormat nf = NumberFormat.getNumberInstance(new Locale("fa"));
System.out.println(nf.format(1234567890));
output:
۱۲۳٬۴۵۶٬۷۸۹
Upvotes: 5