solvit.io

Spell out numbers with PHP to transform numeric values into strings

Solution
$formatter = new NumberFormatter($locale, NumberFormatter::SPELLOUT);
$numberAsString = $formatter->format($number);
Example
$formatter = new NumberFormatter('en', NumberFormatter::SPELLOUT);
$result = $formatter->format(33550336);
// $result = 'thirty-three million five hundred fifty thousand three hundred thirty-six'

$formatter = new NumberFormatter('es', NumberFormatter::SPELLOUT);
$result = $formatter->format(33550336);
// $result = 'treinta y tres millones quinientos cincuenta mil trescientos treinta y seis'

$formatter = new NumberFormatter('ja', NumberFormatter::SPELLOUT);
$result = $formatter->format(33550336);
// $result = '三千三百五十五万三百三十六'
Find more solutions about: , , ,