This week's book giveaway is in the Design forum.We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!

# reading digits from a double

Justin Kuyken
Greenhorn
Posts: 4
I was just wondering how to read say the first digit from a double
for example if my double is 2400....read the 2 and use that and read the 4 and use that seperatly
Is this even possible?
Its for doing the colour code for resistors if anyone has any other ideas
Thanks Justin

Barry Gaunt
Ranch Hand
Posts: 7729
You could use Double.toString(yourDouble) and extract numeric characters with String.subString(). Then convert your numeric characters back to a numeric primitive type.

Otherwise you will have to play around dividing by powers of 10 and taking remainders on division by 10.

David Ulicny
Ranch Hand
Posts: 724
Convert the double to String and read it by single characters.

Chris Allen
Ranch Hand
Posts: 127
Why not something like the following:

I had to put extra code in to stop at the decimal place (since you asked to parse a double instead of an int). Is this what you are looking for?

Wow, didn't realize so many people were looking at the same post!
[ October 25, 2004: Message edited by: Chris Allen ]