Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Invalid Double "#,##"

Tags:

java

android

A user of my app is having a error and the app is crashing

I've looked at the report and it's stating

Caused by: java.lang.NumberFormatException: Invalid double: "1,36"

I have reproduced the data inputted on my app and I don't have the issue at all

I have even asked her to send me her database so i can import the exact data and it still worked okay for me

I'm confused as to where the double is getting formatted like that as I can't see anywhere in my code where it would get formatted with a ,

Any suggestions as to what's going on?

like image 625
Sjharrison Avatar asked Nov 30 '25 06:11

Sjharrison


2 Answers

Simple way is (do it above your parce):

if (str.contains(",")) {
    str.replace(",",".");
}
like image 182
walkmn Avatar answered Dec 02 '25 18:12

walkmn


I just have faced the same problem. I was converting float value to String. Yes, it must be a locale issue. As said in one of the comments, Some locales use , as a decimal separator. Initially I was converting float like-

String.format("%.1f", value);

Then I changed the code to

String.format(Locale.ENGLISH, "%.1f", value);

So, forcing the string to be converted with English local worked for me.

like image 32
Akoder Avatar answered Dec 02 '25 20:12

Akoder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!