Skip to main content

Q about NumberFormat

1 reply [Last post]
Anonymous

Hi All,

In NumberFormat (I use DecimalFormat) there are two methods....

1. format(..) which formats the Number object to the pattern specific to the current locale.
for example,
in English-US -1234 = -1,234 & 1234 = 1,234.
in Arabic-EGYPT -1234 = 1,234- & 1234 = 1,234.
in Macedonian-Macedonia -1234 = (1.234) & 1234 = 1.234.

2.parse(...) which parses the given string MATCHING THE PATTERN OF THE CURRENT LOCALE to the Number object.

If we have a String then we can get the corresponding number object from the parse(...) methods.

Now, coming to my problem... I am having a TextField which accepts only digits, localised plus, minus, decimal separator.
I can get the Number corresponding to the String in the TextField by parse method. But for Arabic Locale the getText returns (if the text in the textfield is -123 -> in arabic it will be 123-) "-123" and so the parsing fails since the number should be 123-. So my question is how to get 123- from the textfield?
Even if we solve that problem...I have one more thing..
In Macedonian, the negative numbers are displayed in -123 but the pattern specified for that one is "(123)"... so if I parse -123 in Macedonian, then the parse fails...So, how to deal with that..
And why is that in Macedonian the display format and the pattern in DecimalFormat is different? getDecimalFormatSymbols().getMinusSign() for Macedonian still returns - and not "()"...

Thanks in advance,
Jana

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
zander
Offline
Joined: 2003-06-13

Topic locked; please only post a question just one time. Thank you.
See http://www.javadesktop.org/forums/thread.jspa?messageID=2193#2193