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]

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;
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.)
> 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