Two Laptop Bag*
The moose likes Beginning Java and the fly likes coding problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "coding problem" Watch "coding problem" New topic
Author

coding problem

MOHAMMAD SALEEM
Greenhorn

Joined: Nov 24, 2001
Posts: 4
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

Joined: Mar 16, 2001
Posts: 986

Some thing like this maybe?


Please ignore post, I have no idea what I am talking about.
Ahmer Arman
Greenhorn

Joined: Nov 23, 2001
Posts: 6
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


Ahmer Arman
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
(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?

"JavaRanch, where the deer and the Certified play" - David O'Meara
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: coding problem