Comma As Decimal Separator

Common bugs/problems with the Android SDK the Emulator and the ADT-Plugin.

Comma As Decimal Separator

Postby gnunn » Wed Sep 30, 2009 1:52 am

I have a program that allows users to enter floating point numbers. One user noted that my program requires that he use a period as the decimal separator even though in his country (Germany) they use the comma instead. No problem, I looked at my code and realized I was constructing a DecimalFormat directly instead of using NumberFormat.getInstance() and changed my code as follows:

formatter = NumberFormat.getNumberInstance();
if (formatter instanceof DecimalFormat) {
DecimalFormat format = (DecimalFormat)formatter;
format.applyPattern(PATTERN);
}

I was going to test it in the emulator and changed my locale to German. While the language changed there was no change to the Number format and it still used the period as the decimal separator. Iterating over NumberFormat.getAvailableLocales() I can see that only English and Japan based countries are returned in the emulator and all those countries use the period not the comma.

Any ideas on how can I test my changes to make sure they work? I can override the decimal separator which works fine for testing the display of numbers, unfortunately the keyboard won't allow me to enter a comma to test the parsing. My personal Android phone only supports English and French. I tried changing it to French but still get the period as the separator, feeling kind of stumped here.
gnunn
Freshman
Freshman
 
Posts: 3
Joined: Sat Jun 13, 2009 7:51 pm

Top

Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: No registered users and 6 guests