I need help with replaceAll for monetary values!

0
String sal = "1500,32";
double salario = 0;
sal.replaceAll( ",", ".");
salario = Double.parseDouble(sal);

Can anyone explain me better about replaceAll? is giving error!

    
asked by anonymous 08.09.2017 / 19:34

1 answer

2

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.

    
08.09.2017 / 19:36