String sal = "1500,32";
double salario = 0;
sal.replaceAll( ",", ".");
salario = Double.parseDouble(sal);
Can anyone explain me better about replaceAll? is giving error!
String sal = "1500,32";
double salario = 0;
sal.replaceAll( ",", ".");
salario = Double.parseDouble(sal);
Can anyone explain me better about replaceAll? is giving error!
The replaceAll
returns a String
and does not change the current one. You need to do the following for your code to work:
String sal = "1500,32";
double salario = 0;
sal = sal.replaceAll(",", ".");
salario = Double.parseDouble(sal);
But keep in mind that there are better ways to convert monetary values.