Number format filter.
All of the formatting options can be left null, in that case the defaults will be used. Supplying any of the parameters will override the defaults set in the environment object.
Twig_Environment $env A Twig_Environment instance:
mixed $number A float/int/string of the number to format:
int $decimal The number of decimal points to display.:
string $decimalPoint The character(s) to use for the decimal point.:
string $thousandSep The character(s) to use for the thousands separator.:
string The formatted number
function twig_number_format_filter(Twig_Environment $env, $number, $decimal = null, $decimalPoint = null, $thousandSep = null) {
$defaults = $env
->getExtension('core')
->getNumberFormat();
if (null === $decimal) {
$decimal = $defaults[0];
}
if (null === $decimalPoint) {
$decimalPoint = $defaults[1];
}
if (null === $thousandSep) {
$thousandSep = $defaults[2];
}
return number_format((double) $number, $decimal, $decimalPoint, $thousandSep);
}