Page 1 of 1
Number to wording
Posted: Thu May 29, 2008 2:23 am
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
Re: Number to wording
Posted: Thu May 29, 2008 4:26 am
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.
Re: Number to wording
Posted: Thu May 29, 2008 4:34 am
by cade
thanks for replying. But is there any reliable function for this? I really have no idea how to construct this
Re: Number to wording
Posted: Thu May 29, 2008 5:58 am
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.
Re: Number to wording
Posted: Thu May 29, 2008 7:31 am
by cade
I have no idea where to start...Hope some experience guys will guide and advise me
Re: Number to wording
Posted: Thu May 29, 2008 7:56 am
by onion2k
Rovas already did.