java.lang.NumberFormatException With Arabic phone language

91 Views Asked by At

When the phone language is Arabic, I get an error on my app:

java.lang.NumberFormatException: For input string: "٣٨.٦٣٤"

When I try to capture the latitude and longitude of a user's location, but when the phone language is in English, I don't get this error.

Here's some code:

this.longitude = Double.parseDouble(UserConfig.getSingleton().getLongitude());
this.latitude = Double.parseDouble(UserConfig.getSingleton().getLatitude());
if (longitude != 0.0 && latitude != 0.0) {
    DecimalFormat formatter = new DecimalFormat("##0.00##");
    UserConfig.getSingleton().setLongitude(formatter.format(longitude));
    UserConfig.getSingleton().setLatitude(formatter.format(latitude)); 
}

I've tried converting latitude and longitude to English fecimal format, and I got this error:

java.lang.NumberFormatException: For input string: "38.634"

I have also tried to make the application language in English, when capturing latitude and longitude to avoid this error, like this:

if (longitude != 0.0 && latitude != 0.0) {
    setDefaultLanguage("en");
    DecimalFormat formatter = new DecimalFormat("##0.00##");
    UserConfig.getSingleton().setLongitude(formatter.format(longitude));
    UserConfig.getSingleton().setLatitude(formatter.format(latitude)); 
}

It worked, but this is not the right solution.

How can I solve this problem?

0

There are 0 best solutions below