PageRenderTime 54ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/libs/Smarty-3.0.7/plugins/modifier.number_format.php

http://sifo.googlecode.com/
PHP | 37 lines | 11 code | 5 blank | 21 comment | 1 complexity | cb990d3c74d65da7bdbc4d3ce3feded8 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, BSD-3-Clause
  1. <?php
  2. /**
  3. * Smarty plugin
  4. * @package Smarty
  5. * @subpackage plugins
  6. */
  7. /**
  8. * Smarty number_format modifier plugin
  9. *
  10. * Type: modifier<br>
  11. * Name: number_format<br>
  12. * Purpose: format strings via number_format
  13. * @author Albert Lombarte
  14. * @param string
  15. * @param string
  16. * @param string
  17. * @param string
  18. * @return string
  19. */
  20. function smarty_modifier_number_format($string, $decimals=2)
  21. {
  22. // Numeric locale vars.
  23. // Remember to change the size_format modifier if you change the locales management here.
  24. setlocale( LC_NUMERIC, Domains::getInstance()->getLanguage() );
  25. $locale = localeconv();
  26. setlocale( LC_NUMERIC, null );
  27. $thousand_separator = ( $locale['thousands_sep'] == '' ) ? '.' : $locale['thousands_sep'];
  28. $decimal_separator = $locale['decimal_point'];
  29. return @number_format( $string, $decimals, $decimal_separator, $thousand_separator );
  30. }
  31. /* vim: set expandtab: */
  32. ?>