I have a difficulty solving my number to words function in php.
<?php
$num = 29.29;
$f = new NumberFormatter("en", NumberFormatter::SPELLOUT);
echo $f->format($num);
//outputs Twenty-nine and two nine
?>
How can I format that to: Twenty-nine and Twenty-nine?
Please help!
First of all, how 29.29 should pronounce is Twenty nine point two nine
. Having said that, if you need to get exactly Twenty-nine and Twenty-nine
, you can use below :
<?php
$num = 29.29;
$exp = explode('.', $num);
$f = new NumberFormatter("en_US", NumberFormatter::SPELLOUT);
echo ucfirst($f->format($exp[0])) . ' and ' . ucfirst($f->format($exp[1]));
//outputs Twenty-nine and Twenty-nine
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With