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!
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.
Try this code:
NumberFormat nf = NumberFormat.getNumberInstance(new Locale("fa"));
System.out.println(nf.format(1234567890));
output:
۱۲۳٬۴۵۶٬۷۸۹
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