NumberHelper.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * NumberHelper.
  11. *
  12. * @package symfony
  13. * @subpackage helper
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. * @version SVN: $Id: NumberHelper.php 7757 2008-03-07 10:55:22Z fabien $
  16. */
  17. function format_number($number, $culture = null)
  18. {
  19. if (is_null($number))
  20. {
  21. return null;
  22. }
  23. $numberFormat = new sfNumberFormat(_current_language($culture));
  24. return $numberFormat->format($number);
  25. }
  26. function format_currency($amount, $currency = null, $culture = null)
  27. {
  28. if (is_null($amount))
  29. {
  30. return null;
  31. }
  32. $numberFormat = new sfNumberFormat(_current_language($culture));
  33. return $numberFormat->format($amount, 'c', $currency);
  34. }
  35. function _current_language($culture)
  36. {
  37. return $culture ? $culture : sfContext::getInstance()->getUser()->getCulture();
  38. }