This week's book giveaway is in the Agile forum. We're giving away four copies of The Software Craftsman and have Sandro Mancuso on-line! See this thread for details.

Do you know what the method Double.valueOf() does with the string that to supply to it? If not, read the API documentation of that method, and you'll understand why giving it a string like "Honey " doesn't work.

Or, with other words: What would you expect it to do?

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus

[Fred]: how is it supposed to convert letters to numbers?

Well, if we get rid of the space at the end of "Honey ", and use an Integer or Long rather than a Double, then we could parse it as a number in base 35 or higher...

Well, if we get rid of the space at the end of "Honey ", and use an Integer or Long rather than a Double, then we could parse it as a number in base 35 or higher...

pffft. Only if we assume that it is not case sensitive. Otherwise we obviously cannot parse this in any number system less than base 61.

Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112

posted

0

Originally posted by Jim Yingst: [Fred]: how is it supposed to convert letters to numbers?

Well, if we get rid of the space at the end of "Honey ", and use an Integer or Long rather than a Double, then we could parse it as a number in base 35 or higher...

Have you tried

Integer.parseInt("Honey", 35);

?

Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671

posted

0

Sure did. It's 26568324. Using base 36, it's 29703562. Beyond that, we exceed Character.MAX_RADIX, it turns out. So saying "base 35 or higher" was a bit misleading, as only 35 or 36 are possible.

Do you get a different result, Ilja?

[Joseph]: Only if we assume that it is not case sensitive.

Hey, I'm still flexible on assumptions here - I haven't even committed to a particular base yet. But if we're talking about the parseXxx() methods (and I did say I was using Integer, or Long), it's documented that these are case insensitive. See details under Character.digit().

My apologies to the original poster, as this little discussion is almost certainly of no interest to you. The point is - what would you expect Double.valueOf() to do here? [ January 10, 2006: Message edited by: Jim Yingst ]

Originally posted by AJKC Shekhawat: String txt = "Honey ";

System.out.println("double for the above string is: " + Double.valueOf(txt));

why doesn't it execute.

Actually, this DOES execute. However, I think you are confused about the result, since it is probably not what you expected. So what DO you expect this to do? Please helpe us help you by providing some more details.