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. Ashwin
Ådne Brunborg
Ranch Hand
Joined: Aug 05, 2005
Posts: 208
posted
0
Note that there are two getNumberInstance methods in NumberFormat:
getNumberInstance
public static final NumberFormat getNumberInstance()
Returns a general-purpose number format for the current default locale.
getNumberInstance
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
posted
0
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.
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.
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 ]