本文整理汇总了PHP中Zend_Locale_Math::floatalize方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Locale_Math::floatalize方法的具体用法?PHP Zend_Locale_Math::floatalize怎么用?PHP Zend_Locale_Math::floatalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Locale_Math
的用法示例。
在下文中一共展示了Zend_Locale_Math::floatalize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toNumber
/**
* Returns a locale formatted number depending on the given options.
* The seperation and fraction sign is used from the set locale.
* ##0.# -> 12345.12345 -> 12345.12345
* ##0.00 -> 12345.12345 -> 12345.12
* ##,##0.00 -> 12345.12345 -> 12,345.12
*
* @param string $input Localized number string
* @param array $options Options: number_format, locale, precision. See {@link setOptions()} for details.
* @return string locale formatted number
* @throws Zend_Locale_Exception
*/
public static function toNumber($value, array $options = array())
{
// load class within method for speed
// require_once 'Zend/Locale/Math.php';
$value = Zend_Locale_Math::normalize($value);
$value = Zend_Locale_Math::floatalize($value);
$options = self::_checkOptions($options) + self::$_options;
$options['locale'] = (string) $options['locale'];
// Get correct signs for this locale
$symbols = Zend_Locale_Data::getList($options['locale'], 'symbols');
$oenc = iconv_get_encoding('internal_encoding');
iconv_set_encoding('internal_encoding', 'UTF-8');
// Get format
$format = $options['number_format'];
if ($format === null) {
$format = Zend_Locale_Data::getContent($options['locale'], 'decimalnumber');
$format = self::_seperateFormat($format, $value, $options['precision']);
if ($options['precision'] !== null) {
$value = Zend_Locale_Math::normalize(Zend_Locale_Math::round($value, $options['precision']));
}
} else {
// seperate negative format pattern when available
$format = self::_seperateFormat($format, $value, $options['precision']);
if (strpos($format, '.')) {
if (is_numeric($options['precision'])) {
$value = Zend_Locale_Math::round($value, $options['precision']);
} else {
if (substr($format, iconv_strpos($format, '.') + 1, 3) == '###') {
$options['precision'] = null;
} else {
$options['precision'] = iconv_strlen(iconv_substr($format, iconv_strpos($format, '.') + 1, iconv_strrpos($format, '0') - iconv_strpos($format, '.')));
$format = iconv_substr($format, 0, iconv_strpos($format, '.') + 1) . '###' . iconv_substr($format, iconv_strrpos($format, '0') + 1);
}
}
} else {
$value = Zend_Locale_Math::round($value, 0);
$options['precision'] = 0;
}
$value = Zend_Locale_Math::normalize($value);
}
if (iconv_strpos($format, '0') === false) {
iconv_set_encoding('internal_encoding', $oenc);
// require_once 'Zend/Locale/Exception.php';
throw new Zend_Locale_Exception('Wrong format... missing 0');
}
// get number parts
$pos = iconv_strpos($value, '.');
if ($pos !== false) {
if ($options['precision'] === null) {
$precstr = iconv_substr($value, $pos + 1);
} else {
$precstr = iconv_substr($value, $pos + 1, $options['precision']);
if (iconv_strlen($precstr) < $options['precision']) {
$precstr = $precstr . str_pad("0", $options['precision'] - iconv_strlen($precstr), "0");
}
}
} else {
if ($options['precision'] > 0) {
$precstr = str_pad("0", $options['precision'], "0");
}
}
if ($options['precision'] === null) {
if (isset($precstr)) {
$options['precision'] = iconv_strlen($precstr);
} else {
$options['precision'] = 0;
}
}
// get fraction and format lengths
if (strpos($value, '.') !== false) {
$number = substr((string) $value, 0, strpos($value, '.'));
} else {
$number = $value;
}
$prec = call_user_func(Zend_Locale_Math::$sub, $value, $number, $options['precision']);
$prec = Zend_Locale_Math::floatalize($prec);
$prec = Zend_Locale_Math::normalize($prec);
if (iconv_strpos($prec, '-') !== false) {
$prec = iconv_substr($prec, 1);
}
if ($prec == 0 and $options['precision'] > 0) {
$prec = "0.0";
}
if ($options['precision'] + 2 > iconv_strlen($prec)) {
$prec = str_pad((string) $prec, $options['precision'] + 2, "0", STR_PAD_RIGHT);
}
if (iconv_strpos($number, '-') !== false) {
$number = iconv_substr($number, 1);
//.........这里部分代码省略.........