I am trying to pass a string with random values with different currency formats:
1,222.50
1.222,50
1222.5
1222,500
1222
To a double to be able to insert it in the database. So far I have the following code:
String a1, a2;
a1 = "1.100,50";
a2 = "1,100.50";
NumberFormat nf = NumberFormat.getInstance();
double number = nf.parse(a1).doubleValue();
double number2 = nf.parse(a2).doubleValue();
System.out.println(number);
System.out.println(number2);
But this is the result I get:
1100.5
1.1
It is not working for me in the English format. I tried the Double.parseDouble(a1)
function but have problems with the Spanish format. Is there any way to pass it to Double regardless of the format it has?