converting String to double

Hi.

In my JSP I easily converted a double I made to a string value, to show percent on a page.

I'm trying to pass it back to my servlet, the string value, that is, which it does just fine.

Now I'm trying to recast that String value back to that of a double, but am getting the error:

java.lang.NumberFormatException: 18.182%

Not sure why.

Can anyone please look at this and let me know what's wrong?

My servlet compiles just fine, and if I put in a try catch block to catch an NFE exception being thrown, it of course just bypasses it altogether.

String appercent$ = request.getParameter("appercent$");

NumberFormat percent = NumberFormat.getPercentInstance();

percent.setMinimumFractionDigits(3);

double apprecentdbl = Double.parseDouble(appercent$);

Thanks!!

[901 byte] By [bpropes20a] at [2007-10-3 3:29:12]
# 1
You need to drop the percent sign before you pass the number to parseDouble().
bckrispia at 2007-7-14 21:22:57 > top of Java-index,Java Essentials,Java Programming...
# 2
Think about it.is "18.182%" a numeric value? No it is not, with that "%" thingy in there.Strip it off before you try the conversion.
warnerjaa at 2007-7-14 21:22:57 > top of Java-index,Java Essentials,Java Programming...
# 3
ok, let me try that.Thanks, guys!! I knew it was something rather fundamental (%) I was overlooking!!Thanks a bunch!!Message was edited by: bpropes20
bpropes20a at 2007-7-14 21:22:57 > top of Java-index,Java Essentials,Java Programming...
# 4
Better than using parseDouble(), use the parse() method in that NumberFormat you just instantiated. That way, it's all but guaranteed that since the format created that string, it will be able to parse it.
Updownquarka at 2007-7-14 21:22:57 > top of Java-index,Java Essentials,Java Programming...
# 5
ok, very good. thanks for that extra tidbit; I'll go back and implement that.
bpropes20a at 2007-7-14 21:22:57 > top of Java-index,Java Essentials,Java Programming...