Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
[#4137] Re-instate code removed during merge
Browse files Browse the repository at this point in the history
- Decimal representations in NumberFormat view helper were broken due to
  bad merge.
  • Loading branch information
weierophinney committed Apr 11, 2013
1 parent 660aa06 commit 2195e7c
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions library/Zend/I18n/View/Helper/NumberFormat.php
Expand Up @@ -19,25 +19,25 @@
class NumberFormat extends AbstractHelper
{
/**
* NumberFormat style to use
* number of decimals to use.
*
* @var integer
*/
protected $formatStyle;
protected $decimals;

/**
* NumberFormat type to use
* NumberFormat style to use
*
* @var integer
*/
protected $formatType;
protected $formatStyle;

/**
* number of decimals to use.
* NumberFormat type to use
*
* @var integer
*/
protected $decimals;
protected $formatType;

/**
* Formatter instances
Expand All @@ -60,13 +60,15 @@ class NumberFormat extends AbstractHelper
* @param int $formatStyle
* @param int $formatType
* @param string $locale
* @param int $decimals
* @return string
*/
public function __invoke(
$number,
$formatStyle = null,
$formatType = null,
$locale = null
$locale = null,
$decimals = null
) {
if (null === $locale) {
$locale = $this->getLocale();
Expand All @@ -77,14 +79,22 @@ public function __invoke(
if (null === $formatType) {
$formatType = $this->getFormatType();
}
if (!is_int($decimals) || $decimals < 0) {
$decimals = $this->getDecimals();
}

$formatterId = md5($formatStyle . "\0" . $locale);
$formatterId = md5($formatStyle . "\0" . $locale . "\0" . $decimals);

if (!isset($this->formatters[$formatterId])) {
$this->formatters[$formatterId] = new NumberFormatter(
$locale,
$formatStyle
);

if ($decimals !== null) {
$this->formatters[$formatterId]->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, $decimals);
$this->formatters[$formatterId]->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
}
}

return $this->formatters[$formatterId]->format($number, $formatType);
Expand Down

0 comments on commit 2195e7c

Please sign in to comment.