Reputation: 141
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;
Upvotes: 4
Views: 1058
Reputation: 141
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);
?>
Upvotes: 2
Reputation:
Assuming you have an array:
$list_of_fees = array("£29", "£50", "£64");;
for($i = 0; $i < 3; $i++)
echo substr($list_of_fees[$i], 1) . " Pounds";
Upvotes: 1
Reputation: 12937
You can use NumberFormatter class with SPELLOUT
:
$nf = new NumberFormatter("en", NumberFormatter::SPELLOUT);
echo $nf->format(1999); // one thousand nine hundred ninety-nine
Upvotes: 7