PageRenderTime 55ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/smarty/lib/Smarty/framework_plugins/modifier.number_format.php

https://github.com/missioncritical/criticali
PHP | 34 lines | 11 code | 3 blank | 20 comment | 3 complexity | 49a45528765b78cd3ae70301676a133a MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /** @package smarty */
  3. /**
  4. * number_format Smarty modifier
  5. *
  6. * Formats a number with decimal and thousand separator
  7. *
  8. * <b>Example:</b>
  9. * <code>
  10. * {$basic_number|number_format} {* 1,234 *}
  11. * ${$currency|number_format:2} {* $1,234.00 *}
  12. * {$euro_style|number_format:2:',':'.'} {* 1.234,00 *}
  13. * </code>
  14. *
  15. * @param float $number The number to format
  16. * @param int $decimals Number of decimal places to include (precision), default is 0
  17. * @param string $decimal_sep Decimal separator character
  18. * @param string $thousands_sep Thousands separator character
  19. *
  20. * @return string
  21. */
  22. function smarty_modifier_number_format($number, $decimals = false, $decimal_sep = false, $thousands_sep = false) {
  23. if ($thousands_sep !== false)
  24. return number_format($number, $decimals, $decimal_sep, $thousands_sep);
  25. if ($decimal_sep !== false)
  26. return number_format($number, $decimals, $decimal_sep);
  27. if ($decimals !== false)
  28. return number_format($number, $decimals);
  29. return number_format($number);
  30. }
  31. ?>