• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

coding problem

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some thing like this maybe?
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic