diff options
Diffstat (limited to 'core/NumberFormatter.php')
-rw-r--r-- | core/NumberFormatter.php | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/core/NumberFormatter.php b/core/NumberFormatter.php index f294508185..141bcdae8d 100644 --- a/core/NumberFormatter.php +++ b/core/NumberFormatter.php @@ -8,8 +8,6 @@ */ namespace Piwik; -use Piwik\Container\StaticContainer; - /** * Class NumberFormatter * @@ -148,6 +146,25 @@ class NumberFormatter extends Singleton return $this->formatNumberWithPattern($pattern, $newValue, $maximumFractionDigits, $minimumFractionDigits); } + + /** + * Formats given number as percent value, but keep the leading + sign if found + * + * @param $value + * @return string + */ + public function formatPercentEvolution($value) + { + $isPositiveEvolution = !empty($value) && ($value > 0 || $value[0] == '+'); + + $formatted = self::formatPercent($value); + + if($isPositiveEvolution) { + return '+' . $formatted; + } + return $formatted; + } + /** * Formats given number as percent value * @param string|int|float $value |