Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/kernel/utility/formatters/formatter.php
Show First 20 Lines • Show All 102 Lines • ▼ Show 20 Line(s) | |||||
* @param string $number | * @param string $number | ||||
* @return float | * @return float | ||||
*/ | */ | ||||
function formatNumber($number) | function formatNumber($number) | ||||
{ | { | ||||
static $comma = null, $thousands = null; | static $comma = null, $thousands = null; | ||||
if ( !isset($comma) || !isset($thousands) ) { | if ( !isset($comma) || !isset($thousands) ) { | ||||
/** @var LanguagesItem $lang */ | |||||
$lang = $this->Application->recallObject('lang.current'); | $lang = $this->Application->recallObject('lang.current'); | ||||
/* @var $lang LanguagesItem */ | |||||
$comma = $lang->GetDBField('DecimalPoint'); | $comma = $lang->GetDBField('DecimalPoint'); | ||||
$thousands = $lang->GetDBField('ThousandSep'); | $thousands = $lang->GetDBField('ThousandSep'); | ||||
} | } | ||||
$number = str_replace($thousands, '', $number); | $number = str_replace($thousands, '', $number); | ||||
$number = str_replace($comma, '.', $number); | $number = str_replace($comma, '.', $number); | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Line(s) | |||||
if ( isset($options['cut_zeros']) && $options['cut_zeros'] ) { | if ( isset($options['cut_zeros']) && $options['cut_zeros'] ) { | ||||
// Remove trailing zeros in decimal part (including "." if any left at the end). | // Remove trailing zeros in decimal part (including "." if any left at the end). | ||||
$value = preg_replace('/\.0+$/', '', $value); | $value = preg_replace('/\.0+$/', '', $value); | ||||
$value = preg_replace('/(\.\d+?)0+$/', '$1', $value); | $value = preg_replace('/(\.\d+?)0+$/', '$1', $value); | ||||
} | } | ||||
} | } | ||||
if (preg_match('#int|integer|double|float|real|numeric#', $options['type'])) { | if (preg_match('#int|integer|double|float|real|numeric#', $options['type'])) { | ||||
/** @var LanguagesItem $lang */ | |||||
$lang = $this->Application->recallObject('lang.current'); | $lang = $this->Application->recallObject('lang.current'); | ||||
/* @var $lang LanguagesItem */ | |||||
return $lang->formatNumber($value); | return $lang->formatNumber($value); | ||||
} | } | ||||
elseif ($options['type'] == 'string') { | elseif ($options['type'] == 'string') { | ||||
$value = $this->_replaceFCKLinks($value, $options, $original_format); | $value = $this->_replaceFCKLinks($value, $options, $original_format); | ||||
} | } | ||||
return $value; | return $value; | ||||
▲ Show 20 Lines • Show All 105 Lines • Show Last 20 Lines |