File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Formatting Arabic numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Formatting Arabic numbers" Watch "Formatting Arabic numbers" New topic

Formatting Arabic numbers

Ash Kondhalkar
Ranch Hand

Joined: Jun 14, 2006
Posts: 43
Hi Edwin,

I have a string which contains Arabic numbers and now I want to format it. So I am using NumberFormat class and using its getNumberInstance method.

This method returns object of type NumberFormat. I am calling format method on this object, to format this Arabic number, the issue I am facing is format method doesn�t accept string value so I am passing integer value, using new Integer(string).intValue();

But when I pass this to format method it returns me formatted numbers but they are now converted into English.
Actually new Integer(string).intValue() returns English numbers itself.
Will anyone kindly shed some light on this?

Thanks for your valuable time.
Ådne Brunborg
Ranch Hand

Joined: Aug 05, 2005
Posts: 208
Note that there are two getNumberInstance methods in NumberFormat:


public static final NumberFormat getNumberInstance()

Returns a general-purpose number format for the current default locale.


public static NumberFormat getNumberInstance(Locale inLocale)

Returns a general-purpose number format for the specified locale.

I assume you are using the first, no-parameter method, have you tried using the second, with a Locale parameter? A Locale object "represents a specific geographical, political, or cultural region."

Entia non sunt multiplicanda praeter necessitatem
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
Hi Ash.

Using a NumberFormat with a "ar" or "ar_SA" locale probably will not help, since this locale just states the way a number should be formatted (decimal separator, currency symbols, etc), but it does not alter the way the numbers look.

See java.text.DecimalFormatSymbols to see what you can really customized in this regard.

Java provides support for certain languages so that the numbers can be expressed in different characters. This is one of the uses Java gives to the the "variant" property in the java.util.Locale class.

For instance, if you want to format a number using thai characters then you have to create a locale this way: Locale l = new Locale("th","TH","TH").

Unfortunately, if you invoke Locale.getAvailableLocales() you will discover there is not such special support for arabic. Therefore, you will have to create a fuction yourself that converts every character in the resulting string to you arabic numbers.

See also Supported Locales for further details.

Pretty much like the one that was already suggested in previous posts, but instead of coverting a arabic number to an european number, it should work the other way round.

See previous post here
[ December 19, 2006: Message edited by: Edwin Dalorzo ]
I agree. Here's the link:
subject: Formatting Arabic numbers
It's not a secret anymore!