Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
    Bookmark Topic Watch Topic
  • New Topic

coding problem

 
MOHAMMAD SALEEM
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Report post to moderator
double d = 546954.14;
could anyone please tell me how do I pick up the individual values
The output format is :
5 hundred 46 thousand 9 hundred 54 dollars 14 cents
A full code would be appreciated.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Report post to moderator
hmmmm . . . homework.
Perhaps you could convert it to a String using the toString() method of Double. Then you could identify the value of each byte by using the charAt(index) method of String.
You can find the number of chars in the whole thing by taking the String above and using the length() method. For instance your number will be 9 chars long. The last three will always be the decimal and the cents. So the "dollars" will always be at (length - 4) and (length - 5). The hundreds will always be at (length -6) the thousands and (length -8) and (length - 7) and the hundred thousands at (length - 10) and (length - 9). etc.
Is that enough of a start?
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Report post to moderator
MOHAMMAD
You already asked this question and received two replys here: http://www.javaranch.com/ubb/Forum33/HTML/004133.html.
Please dont repost the same question multiple times, if you didn't receive a satisfactory answer post a reply to the current thread clarifying your question or telling why it was satisfactory. If you create new threads all the time the people that did respond will think they are being ignored.

------------------
Dave
Sun Certified Programmer for the Java� 2 Platform
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Report post to moderator
You have already posted this question. And two people have given you clues. Most likely that is about as much help as you are going to get until you post some code. http://www.javaranch.com/ubb/Forum33/HTML/004133.html
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic