converting string to double
i need help for a class project i am working on. the program is supposed to estimate the amount of taxes that someone needs to pay. i used a formatted text field to give the user a place to enter in their yearly salary. I retrieve the text from the textfield and i save it into a String. then i use the parseDouble() method to try to change the string into a double.
//get the string for salary
String salary2 = amountField.getText();
//convert the string to a double, doesnt work
double salary = parseDouble(salary2);
and i get
E:\tax\taxes.java:78: cannot resolve symbol
symbol : method parseDouble (java.lang.String)
location: class taxes
double salary = parseDouble(salary2);
can someone help me to make this work please?
[792 byte] By [
neeloy] at [2007-9-30 21:22:04]

> double salary = parseDouble(salary2);
This line attempts to call a method defined in the current class. Did you define a parseDouble method? The compiler can't find it.
May be you intended to call the static parseDouble method that is in the Double class. If that's what you meant, then the call should be Double.parseDouble(salary2);
This tells the compiler to find the static parseDouble method inside the Double class.
> Hi neeloy,
> calling method parseDouble (java.lang.String) means
> by default compiler checks it in ur default packages
> list ( which is java.lang) unfortunately u cant find
> it in java.lang.
> hence u better try to use
> java.lang.Double.parseDouble(String). It will work
>
The compiler does not look for methods in default packages. It looks in default packages for classes. Using java.lang.Double instead of just plain Double is not needed since Double is in java.lang. This is not a problem with the compiler finding java.lang package.