NumberFormatException in European versions of Android?

I have an application that runs the following two lines of code at startup:

DecimalFormat decim = new DecimalFormat("#.00");
return Double.parseDouble(decim.format(totalNumberOfCredits));

When I run the application on my American phone, the value decim.format(totalNumberOfCredits)is equal .00.

However, in my Google Play Developer Console, I have a dozen crashes, all of which look like this:

Caused by: java.lang.NumberFormatException: Invalid double: ",00"
at java.lang.StringToReal.invalidReal(StringToReal.java:63)
at java.lang.StringToReal.parseDouble(StringToReal.java:269)
at java.lang.Double.parseDouble(Double.java:295)

Is it possible that DecimalFormat produces a comma version of the decimal number on European phones?

+3
source share
3 answers

Is it possible that DecimalFormat produces a comma version of the decimal number on European phones?

Yes, absolutely. What he had to do , in the end:

DecimalFormat . DecimalFormat, .

, factory NumberFormat, getNumberInstance. NumberFormat .

, " Android" - Android , , .

, , :

DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(Locale.US);
DecimalFormat format = new DecimalFormat("#.00", symbols);

, , - , ? , . ? ( , totalNumberOfCredits, .)

+7
    public double getTwoPointDecimal(double value) {        
           DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.US);      
           return Double.parseDouble(new DecimalFormat("##.##", symbols).format(value));
    }

,

+2

double unit = Float.parseFloat(String); DecimalFormat decimal = new DecimalFormat ( "##. ###" ). Format (unit);

,

0

All Articles