Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/kernel/utility/formatters/formatter.php
Show First 20 Lines • Show All 174 Lines • ▼ Show 20 Line(s) | |||||
if (isset($format) && $format) { | if (isset($format) && $format) { | ||||
if ( substr($format, -1) === 'f' ) { | if ( substr($format, -1) === 'f' ) { | ||||
// High precision formats (e.g. '%01.20f') are not supported to keep code below as fast as possible. | // High precision formats (e.g. '%01.20f') are not supported to keep code below as fast as possible. | ||||
$value = round($value, substr($format, -2, 1)); | $value = round($value, substr($format, -2, 1)); | ||||
} | } | ||||
$value = sprintf($format, $value); | $value = sprintf($format, $value); | ||||
if ( isset($options['cut_zeros']) && $options['cut_zeros'] ) { | if ( isset($options['keep_cents']) && $options['keep_cents'] ) { | ||||
preg_match('/(\d+\.\d{' . $options['keep_cents'] . '})(\d+)?/', $value, $regs); | |||||
// When "keep_cents" option matches format's precision, there will be an "Undefined index: 2" notice. | |||||
if ( rtrim($regs[2], '0') === '' ) { | |||||
$value = $regs[1]; | |||||
} | |||||
else { | |||||
// Remove trailing zeros in decimal part. | |||||
$value = preg_replace('/(\.\d+?)0+$/', '$1', $value); | |||||
} | |||||
} | |||||
elseif ( 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 */ | /** @var LanguagesItem $lang */ | ||||
▲ Show 20 Lines • Show All 114 Lines • Show Last 20 Lines |