Convert number to letter with php [duplicate]
Possible Duplicate:
Converting a number (1, 2, 3) to a string (one, two, three) in PHP
I'm programming an invoice script. I'm looking for a php script that convert number to letter. Exemple, the invoice show this value : 155€
The script put automatically: ONE HUNDRED FIFTY FIVE
Any ideas ?
Thank you :)
Solution 1:
Can use
- http://pear.php.net/package/Numbers_Words
With Numbers_Words class you can convert numbers written in arabic digits to words in several languages. You can convert an integer between -infinity and infinity. If your system does not support such long numbers you can call Numbers_Words::toWords() with just a string.
With the Numbers_Words::toCurrency($num, $locale, 'USD') method you can convert a number (decimal and fraction part) to words with currency name.
Solution 2:
Try looking into NumberFormatter for PHP.
Sample Script:
<?php
$f = new NumberFormatter("en", NumberFormatter::SPELLOUT);
echo $f->format(123456);
?>
Produces the result:
one hundred twenty-three thousand four hundred fifty-six