I would like to convert integer to words, for eg: 29 would become TWENTY NINE and 50 would be FIFTY. How can I achieve this using PHP?
Here is what I have so far but it isn't giving the desired output.
$fees_so = $form_data_fees['field']['4'];
$feesInWords = strval($fees_so);
echo $feesInWords;
You can use NumberFormatter class with SPELLOUT:
$nf = new NumberFormatter("en", NumberFormatter::SPELLOUT);
echo $nf->format(1999); // one thousand nine hundred ninety-nine
I eventually found a solution using the code from @aniket-sahrawat with a little tweaking
Here is the code in case anyone needs this in future...
<?php
$fees_so = $form_data_fees['field']['4'];
$words = filter_var($fees_so, FILTER_SANITIZE_NUMBER_INT);
$nf = new NumberFormatter("en", NumberFormatter::SPELLOUT);
echo $nf->format($words);
?>
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