Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

coding problem

 
MOHAMMAD SALEEM
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could anyone help me out in the coding of this problem:-
double d=546958.98;
The output should be:-
5 Hundred 46 Thousand 9 Hundred 58 Dollars and 98 Cents
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some thing like this maybe?
 
Ahmer Arman
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another logic to do this.
Change your double value to String value, separeate the integer part from string, then pick from the first characters.
Make two String Arrays:
1) for numbers in words from "One" to "Ninty Nine".
2) for units "Hundreds" to so on as many u want....
check if the length is divisible by 3 or not
if yes then pick only one character from string, change it to integer and access direct to the number string array("One..."Ninty Nine"), check also for length remaining after every interation of the loop.
Pick the unit value from loop for(int loop=number.length/2 .
Ahmer Arman
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(copied from the other thread)
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic