• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Formatting Arabic numbers

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Ashwin
 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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."
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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'm sure glad that he's gone. Now I can read this tiny ad in peace!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic