NumberFormatter in php code example

Example: numberformatter php

/* PHP class to format numbers, currencies, percentages et cetera according
to the specified or default locale class. One must install and enable PHP
intl extension to utilize the NumberFormatter class. */

$num = 1234567.891234567891;

$nf = new NumberFormatter('en_US', NumberFormatter::DECIMAL);
echo $nf->format($num);

$nf = new NumberFormatter('uk_UA', NumberFormatter::CURRENCY);
echo $nf->formatCurrency($num, 'UAH');

$nf = new NumberFormatter('lt_LT', NumberFormatter::SPELLOUT);
echo $nf->format($num);

$nf = new NumberFormatter('en_US', NumberFormatter::DURATION);
echo $nf->format($num);

$nf = new NumberFormatter('fr_FR', NumberFormatter::DECIMAL);
$nf->setPattern('#,##0.### kg');
echo $nf->format($num);

Tags:

Php Example