"Jens B. Jorgensen" wrote: > Goeman Stefan wrote: > > > Hello, > > > > I know, this is not really a question about Debian. > > You got that right. > > > The question is actually very simple. I want to convert a > > string to a double. > > > > There is a method in the java.lang.Double named > > parseDouble > > > > When I insert a line like > > double d = Double.parseDouble(x); > > in my program, I get the error: > > Method parseDouble(java.lang.String) not found in class java.lang.Double > > This method is only in java.lang.Double since JDK 1.2. You must have an > earlier > version. > > > There is also another method in the java.lang.Double class that should do > > the same, > > i.e. method valueOf > > > > Now, when I insert a line like > > double d = Double.valueOf(x); > > in the program, i get the error: > > Incompatible type for declaration. Can't convert java.lang.Double to double. > > Yup, because Double.valueOf() returns type java.lang.Double, not simply > double. What > you want is: > > double d = Double.valueOf(x).doubleValue(); > > > in the program, > > (Casting does not solve this problem) > > Nope. There's no such thing as > > Double::operator double() > > such as there _might_ be if this were C++, which it isn't. > > > Does anybody know what is going wrong?? > > > > Greetings, > > > > Stefan. > > -- > Jens B. Jorgensen > [EMAIL PROTECTED] > > -- > Unsubscribe? mail -s unsubscribe [EMAIL PROTECTED] < /dev/null
You also can use the following which in my opinion is simpler: String num = 3.4235; double num1 = Double.parseDouble(num); This is supported only in Java 2.