本文整理汇总了PHP中CakeNumber::_numberFormatSupport方法的典型用法代码示例。如果您正苦于以下问题:PHP CakeNumber::_numberFormatSupport方法的具体用法?PHP CakeNumber::_numberFormatSupport怎么用?PHP CakeNumber::_numberFormatSupport使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CakeNumber
的用法示例。
在下文中一共展示了CakeNumber::_numberFormatSupport方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _numberFormat
/**
* Alternative number_format() to accommodate multibyte decimals and thousands < PHP 5.4
*
* @param float $value
* @param integer $places
* @param string $decimals
* @param string $thousands
* @return string
*/
protected static function _numberFormat($value, $places = 0, $decimals = '.', $thousands = ',')
{
if (!isset(self::$_numberFormatSupport)) {
self::$_numberFormatSupport = version_compare(PHP_VERSION, '5.4.0', '>=');
}
if (self::$_numberFormatSupport) {
return number_format($value, $places, $decimals, $thousands);
}
$value = number_format($value, $places, '.', '');
$after = '';
$foundDecimal = strpos($value, '.');
if ($foundDecimal !== false) {
$after = substr($value, $foundDecimal);
$value = substr($value, 0, $foundDecimal);
}
while (($foundThousand = preg_replace('/(\\d+)(\\d\\d\\d)/', '\\1 \\2', $value)) != $value) {
$value = $foundThousand;
}
$value .= $after;
return strtr($value, array(' ' => $thousands, '.' => $decimals));
}