• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to force app to use US Locale?

midtoad

Lurker
I do a bunch of numerical calculations in my app, and it force-closes when the user has chosen a locale (e.g. French) where a comma is used instead of a dot for the decimal separator. To resolve this, I could either try to make my app Locale-aware (which seems like a daunting task) or else have the app ignore the user's locale and always use US locale for its internal work. How do I do the latter?

thanks
S
 
Make sure the application only allows it to turn an input into a number if it is a number

Ex: no , !# etc, do this by clicking on (in xml) the edittext, then input type, then select the three that apply to numbers, I forget off hand which they are, but you'll recognize them when u see them. This allows a user to only type numbers, period (decimal point), or a - as a negitive sign at the beginning, and that will solve your problem
 
Thanks for that suggestion, and it would be helpful if my users actually were entering numbers. Instead, they are only picking entries in a list, from which calculations are then made and displayed. The problem is that if they select, say 162.5 from a list, and this number is then multiplied internally by, say 2, an exception will result if the French locale is being used because 162.5 is not a correct number format in that locale. Hence I want my app to override the French locale and use US locale instead.
 
I'm thinking you could do something along the lines of get the number as 231,24 (, as .) Then getStringValueOf(), then search the string from string.charAt(0) to string.charAt(string.length) or along those lines, posting from my phone. When getting charAt(pos), check if its a , and if it is, change.it to a . , then do ur equasions, then do the same thing, but backwards. Check for a . And replace it with a ,
 
Back
Top Bottom