NumberHelper.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. }