Double.parseDouble

the user enters a premium amount and then I want to use that amount in a calcuation; can't I parseDouble it like this? apparently not, because when I try to multiply, I get an error "the operator * is undefined for argument type(s) double, String. I have done this in the past, what is wrong?

String pAmount = JOptionPane.showInputDialog("Enter the premium amount:");

double num = EndCancelDiffCounter;

double denom = counter;

double result = num/denom;

Double.parseDouble(pAmount);

double refund = result * pAmount;

[717 byte] By [kalugaa] at [2007-11-26 19:55:35]
# 1

parseDouble returns a double value. It does not magically convert your String reference to a double type.

double result = num/denom;

double amount = Double.parseDouble(pAmount);

double refund = result * amount;

CeciNEstPasUnProgrammeura at 2007-7-9 22:48:51 > top of Java-index,Java Essentials,New To Java...
# 2

parseDouble returns a double, it does not change the String given froma String to a double. You need to store that result (return value) in a new double variable and perform your calculation with that.

Edit: Man I'm slow. (I had to check that parseDouble returned a double and not a Double. I wasn't 100% sure, as I'm a little daft this morning.)

masijade.a at 2007-7-9 22:48:51 > top of Java-index,Java Essentials,New To Java...
# 3
Read the [url= http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Double.html# http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Double.html#parseDouble(java.lang.String)]Double API doco[/url] again.doesn't return a value?
corlettka at 2007-7-9 22:48:51 > top of Java-index,Java Essentials,New To Java...
# 4

> parseDouble returns a double, it does not change the

> String given froma String to a double. You need to

> store that result (return value) in a new double

> variable and perform your calculation with that.

>

> Edit: Man I'm slow. (I had to check that

> parseDouble returned a double and not a Double. I

> wasn't 100% sure, as I'm a little daft this morning.)

I see, thank you

kalugaa at 2007-7-9 22:48:51 > top of Java-index,Java Essentials,New To Java...