Search code examples
phpnumber-formatting

Convert number | integer to words


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;

Solution

  • You can use NumberFormatter class with SPELLOUT:

    $nf = new NumberFormatter("en", NumberFormatter::SPELLOUT);
    echo $nf->format(1999); // one thousand nine hundred ninety-nine