Reputation: 872
Please help to convert the string value ("0.25000%") to double value.
0.25000% = 0.0025 (need to get this value as double)
String num = "0.25000%";
double d = Double.parseDouble(num);//does not work
Upvotes: 2
Views: 119
Reputation: 822
String num = "0.25000%";
BigDecimal d = new BigDecimal(num .trim().replace("%","")).divide(BigDecimal.valueOf(100));//no problem BigDecimal
this can convert for decimal.
Upvotes: 2
Reputation: 35577
You can try this
String num = "0.25000%";
double d = Double.parseDouble(num.replace("%","")); // remove %
System.out.println(d);
Out put:
0.25
For your edit:
You can divide final answer by 100
System.out.println(d/100);
Now out put:
0.0025
Upvotes: 5
Reputation: 2124
Remove the %
character and divide by 100
String num = "0.25000%";
double d = Double.parseDouble(num.replace("%","")) / 100;
Upvotes: 1