You are here

function twig_number_format_filter in Translation template extractor 6.3

Same name and namespace in other branches
  1. 7.3 vendor/Twig/Extension/Core.php \twig_number_format_filter()

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.

Parameters

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.:

Return value

string The formatted number

1 string reference to 'twig_number_format_filter'
Twig_Extension_Core::getFilters in vendor/Twig/Extension/Core.php
Returns a list of filters to add to the existing list.

File

vendor/Twig/Extension/Core.php, line 582

Code

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);
}