0
String sal = "1500,32";
double salario = 0;
sal.replaceAll( ",", ".");
salario = Double.parseDouble(sal);
Can anyone explain to me better the replaceAll? is giving error!
0
String sal = "1500,32";
double salario = 0;
sal.replaceAll( ",", ".");
salario = Double.parseDouble(sal);
Can anyone explain to me better the replaceAll? is giving error!
3
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 bear in mind that there are better ways to convert monetary values.
Browser other questions tagged java
You are not signed in. Login or sign up in order to post.
Thank you very much, man!
– Joel Medeiros
@Joelmedeiros don’t forget to accept the answer so you can help other people with similar doubt.
– Sorack