Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reading digits from a double

 
Justin Kuyken
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Convert the double to String and read it by single characters.
 
Chris Allen
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic