[android-developers] Re: NumberFormat and comma as decimal separator
Thanks for the comments, I check with my user in Germany and he confirmed that he cannot type the comma into a decimal field in Android. The issue is arising for me because when I copy the text into the edit field I convert it into a localized String which has the comma in it. Once this gets into the edit field it makes my current usage of Double.valueOf fail for the reasons discussed above. I'll probably just change my code to enforce using the period everywhere for consistency until this issue gets fixed in a later version of Android. On Sep 30, 1:30 pm, Streets Of Boston flyingdutc...@gmail.com wrote: I meant 'valueOf' method of the various Number subclasses... :-) You're right. I just took a look at the code that is executed by Double.valueOf(...). It is hard-coded for using periods asdecimalseperators. On Sep 30, 12:55 pm, Gerald gerald.b.n...@gmail.com wrote: There is no valueOf method in the Number class. If I use the Double.valueOf method it fails to work according to my users. The Android docs on Double.valueOf are pretty thin, however the JDK docs are pretty clear that this accepts a string with a number formatted according to the Java Language Specifications and thus does not accept a localized number string. Gerald --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: NumberFormat and comma as decimal separator
I think that using the Number.valueOf and Number.toString methods should work fine. The system should deal with the currently installed and active locale. Unless you're creating an app that needs to deal with multiple locales at the same time or do some fancy formatting, i wouldn't bother much with NumberFormats and such. Just let the java core runtime handle it. On Sep 29, 8:53 pm, Gerald gerald.b.n...@gmail.com wrote: I have a program that allows users to enter decimal 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 then 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 in a numeric field 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. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: NumberFormat and comma as decimal separator
It's a Android bug. See http://code.google.com/p/android/issues/detail?id=2626 On Sep 30, 6:30 pm, Streets Of Boston flyingdutc...@gmail.com wrote: I think that using the Number.valueOf and Number.toString methods should work fine. The system should deal with the currently installed and active locale. Unless you're creating an app that needs to deal with multiple locales at the same time or do some fancy formatting, i wouldn't bother much with NumberFormats and such. Just let the java core runtime handle it. On Sep 29, 8:53 pm, Gerald gerald.b.n...@gmail.com wrote: I have a program that allows users to enter decimal 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 then 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 in a numeric field 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. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: NumberFormat and comma as decimal separator
There is no valueOf method in the Number class. If I use the Double.valueOf method it fails to work according to my users. The Android docs on Double.valueOf are pretty thin, however the JDK docs are pretty clear that this accepts a string with a number formatted according to the Java Language Specifications and thus does not accept a localized number string. Gerald --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: NumberFormat and comma as decimal separator
I meant 'valueOf' method of the various Number subclasses... :-) You're right. I just took a look at the code that is executed by Double.valueOf(...). It is hard-coded for using periods as decimal seperators. On Sep 30, 12:55 pm, Gerald gerald.b.n...@gmail.com wrote: There is no valueOf method in the Number class. If I use the Double.valueOf method it fails to work according to my users. The Android docs on Double.valueOf are pretty thin, however the JDK docs are pretty clear that this accepts a string with a number formatted according to the Java Language Specifications and thus does not accept a localized number string. Gerald --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---