Number to wording

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cade
Forum Commoner
Posts: 55
Joined: Tue Jul 03, 2007 8:18 pm

Number to wording

Post by cade »

I really hope someone would teach me how to do this.

If you are aware, most of the bank will print the amount of sum of money you deposit or withdraw with wording...

Example: USD8,572.20

Output: EIGHT THOUSAND FIVE HUNDRED SEVENTY TWO AND TWENTY CENTS

how do i achive this with php?

thanks in advance
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Re: Number to wording

Post by Rovas »

Divide the number by 10 to separate the milions, thousand, hundreds, cents. The results put in an array then using for each division (i.e. millions thousands) make use switch to output the correct word for the number in that position.
For example

Code: Select all

 
you have 813 dollars 
if you divide by ten 
you get this array [dollars]=3, [decimal]=1; [hundreds]=8  
switch($a[dollars])
case "0":
case "1": valueString="one";Break;
case "2": valueString="two";Break;
etc
 
This is simple but resource and time consuming. I don' t have a better idea.
cade
Forum Commoner
Posts: 55
Joined: Tue Jul 03, 2007 8:18 pm

Re: Number to wording

Post by cade »

thanks for replying. But is there any reliable function for this? I really have no idea how to construct this
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Number to wording

Post by onion2k »

cade wrote:thanks for replying. But is there any reliable function for this? I really have no idea how to construct this
There's nothing built into PHP to do it.. You'll have to write it yourself or find an example online somewhere.
cade
Forum Commoner
Posts: 55
Joined: Tue Jul 03, 2007 8:18 pm

Re: Number to wording

Post by cade »

I have no idea where to start...Hope some experience guys will guide and advise me
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Number to wording

Post by onion2k »

Rovas already did.
Post Reply