PageRenderTime 43ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/jelix/plugins/tpl/common/modifier.number_format.php

https://bitbucket.org/jelix/jelix-trunk/
PHP | 38 lines | 17 code | 1 blank | 20 comment | 5 complexity | 36f139805adabbf899bbba32e552f5a8 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause, JSON, GPL-3.0, LGPL-3.0
  1. <?php
  2. /**
  3. * jTpl plugin that wraps PHP number_format function
  4. * @package jelix
  5. * @subpackage jtpl_plugin
  6. * @author Julien Issler
  7. * @contributor Mickael Fradin
  8. * @copyright 2008-2010 Julien Issler, 2009 Mickael Fradin
  9. * @link http://www.jelix.org
  10. * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
  11. * @since 1.1
  12. */
  13. /**
  14. * NumberFormat plugin for jTpl that wraps PHP number_format function
  15. *
  16. * @param float $number the number to format
  17. * @param int $decimals the number of decimals to return
  18. * @param string $dec_point the separator string for the decimals
  19. * @param string $thousands_sep the separator string for the thousands
  20. * @return string
  21. */
  22. function jtpl_modifier_common_number_format($number, $decimals=0, $dec_point=false, $thousands_sep=false){
  23. if ($dec_point == false) {
  24. $dec_point = jLocale::get('jelix~format.decimal_point');
  25. }
  26. if ($thousands_sep === false) {
  27. $thousands_sep = jLocale::get('jelix~format.thousands_sep');
  28. if(strlen($thousands_sep) > 1){
  29. $real_thousands_sep = $thousands_sep;
  30. $thousands_sep = '#';
  31. }
  32. }
  33. $number = number_format($number, $decimals, $dec_point, $thousands_sep);
  34. if(isset($real_thousands_sep))
  35. return str_replace($thousands_sep, $real_thousands_sep, $number);
  36. return $number;
  37. }