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 sc开发者_StackOverflow社区ript put automatically: ONE HUNDRED FIFTY FIVE
Any ideas ?
Thank you :)
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.
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
Or, if you don't have PEAR or don't want to use PEAR you can try:
http://krishnasrikanth.in/2010/04/10/number-to-words-in-php
Greetings, and good luck ;)
Usage:
$converter=new NumbWordter();
echo $converter->convert(1823912);
// echoes - One million, eight hundred and twenty three thousand, nine hundred and twelve
精彩评论