本文整理汇总了PHP中Zend_Locale_Math::normalize方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Locale_Math::normalize方法的具体用法?PHP Zend_Locale_Math::normalize怎么用?PHP Zend_Locale_Math::normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Locale_Math
的用法示例。
在下文中一共展示了Zend_Locale_Math::normalize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
//.........这里部分代码省略.........
示例2: 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
*/
public static function toNumber($value, array $options = array())
{
$value = Zend_Locale_Math::normalize($value);
$options = array_merge(self::$_Options, self::checkOptions($options));
if ($options['locale'] instanceof Zend_Locale) {
$options['locale'] = $options['locale']->toString();
}
// Get correct signs for this locale
$symbols = Zend_Locale_Data::getContent($options['locale'], 'numbersymbols');
iconv_set_encoding('internal_encoding', 'UTF-8');
// Get format
$format = $options['number_format'];
if ($format === null) {
$format = Zend_Locale_Data::getContent($options['locale'], 'decimalnumberformat');
$format = $format['default'];
if (iconv_strpos($format, ';') !== false) {
if (call_user_func(Zend_Locale_Math::$comp, $value, 0) < 0) {
$format = iconv_substr($format, iconv_strpos($format, ';') + 1);
} else {
$format = iconv_substr($format, 0, iconv_strpos($format, ';'));
}
}
} else {
// seperate negative format pattern when avaiable
if (iconv_strpos($format, ';') !== false) {
if (call_user_func(Zend_Locale_Math::$comp, $value, 0) < 0) {
$format = iconv_substr($format, iconv_strpos($format, ';') + 1);
} else {
$format = iconv_substr($format, 0, iconv_strpos($format, ';'));
}
}
if (strpos($format, '.')) {
if (is_numeric($options['precision'])) {
$value = round($value, $options['precision']);
} else {
if (substr($format, strpos($format, '.') + 1, 3) == '###') {
$options['precision'] = null;
} else {
$options['precision'] = strlen(substr($format, strpos($format, '.') + 1, strrpos($format, '0') - strpos($format, '.')));
$format = substr($format, 0, strpos($format, '.') + 1) . '###' . substr($format, strrpos($format, '0') + 1);
}
}
} else {
$value = round($value, 0);
$options['precision'] = 0;
}
}
// set negative sign
if (call_user_func(Zend_Locale_Math::$comp, $value, 0) < 0) {
if (iconv_strpos($format, '-') === false) {
$format = $symbols['minus'] . $format;
} else {
$format = str_replace('-', $symbols['minus'], $format);
}
}
// get number parts
if (strlen($value) != strlen(round($value, 0))) {
if ($options['precision'] === null) {
$precstr = iconv_substr($value, strlen(round($value, 0)) + 1);
} else {
$precstr = iconv_substr($value, strlen(round($value, 0)) + 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
$preg = call_user_func(Zend_Locale_Math::$sub, $value, '0', 0);
$prec = call_user_func(Zend_Locale_Math::$sub, $value, $preg, $options['precision']);
if (iconv_strpos($prec, '-') !== false) {
$prec = iconv_substr($prec, 1);
}
if ($options['precision'] + 2 > strlen($prec)) {
$prec = $prec . str_pad("0", $options['precision'] - iconv_strlen($prec), "0");
}
$number = call_user_func(Zend_Locale_Math::$sub, $value, $prec, 0);
if (iconv_strpos($number, '-') !== false) {
$number = iconv_substr($number, 1);
//.........这里部分代码省略.........
示例3: 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
*/
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);
$options = array_merge(self::$_Options, self::checkOptions($options));
if ($options['locale'] instanceof Zend_Locale) {
$options['locale'] = $options['locale']->toString();
}
// Get correct signs for this locale
$symbols = Zend_Locale_Data::getList($options['locale'], 'symbols');
iconv_set_encoding('internal_encoding', 'UTF-8');
// Get format
$format = $options['number_format'];
if ($format === null) {
$format = Zend_Locale_Data::getContent($options['locale'], 'decimalnumber');
if (iconv_strpos($format, ';') !== false) {
if (call_user_func(Zend_Locale_Math::$comp, $value, 0) < 0) {
$format = iconv_substr($format, iconv_strpos($format, ';') + 1);
} else {
$format = iconv_substr($format, 0, iconv_strpos($format, ';'));
}
}
} else {
// seperate negative format pattern when available
if (iconv_strpos($format, ';') !== false) {
if (call_user_func(Zend_Locale_Math::$comp, $value, 0) < 0) {
$format = iconv_substr($format, iconv_strpos($format, ';') + 1);
} else {
$format = iconv_substr($format, 0, iconv_strpos($format, ';'));
}
}
if (strpos($format, '.')) {
if (is_numeric($options['precision'])) {
$value = Zend_Locale_Math::round($value, $options['precision']);
} else {
if (substr($format, strpos($format, '.') + 1, 3) == '###') {
$options['precision'] = null;
} else {
$options['precision'] = strlen(substr($format, strpos($format, '.') + 1,
strrpos($format, '0') - strpos($format, '.')));
$format = substr($format, 0, strpos($format, '.') + 1) . '###'
. substr($format, strrpos($format, '0') + 1);
}
}
} else {
$value = Zend_Locale_Math::round($value, 0);
$options['precision'] = 0;
}
$value = Zend_Locale_Math::normalize($value);
}
// get number parts
if (strlen($value) != strlen(Zend_Locale_Math::round($value, 0))) {
if ($options['precision'] === null) {
$precstr = iconv_substr($value, strlen(Zend_Locale_Math::round($value, 0)) + 1);
} else {
$precstr = iconv_substr($value, strlen(Zend_Locale_Math::round($value, 0)) + 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']);
if (iconv_strpos($prec, '-') !== false) {
//.........这里部分代码省略.........
示例4: 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
*/
public static function toNumber($value, array $options = array())
{
print "\ntoNumber";
print "\n--------";
// load class within method for speed
require_once 'Zend/Locale/Math.php';
$value = Zend_Locale_Math::normalize($value);
print "\n1-Value :'" . $value . "'";
$options = array_merge(self::$_Options, self::checkOptions($options));
if ($options['locale'] instanceof Zend_Locale) {
$options['locale'] = $options['locale']->toString();
}
print "\n2-Locale:'" . $options['locale'] . "'";
// Get correct signs for this locale
$symbols = Zend_Locale_Data::getList($options['locale'], 'symbols');
iconv_set_encoding('internal_encoding', 'UTF-8');
// Get format
$format = $options['number_format'];
print "\n3-Format1:'" . $format . "'";
if ($format === null) {
$format = Zend_Locale_Data::getContent($options['locale'], 'decimalnumber');
print "\n3-Format2:'" . $format . "'";
if (iconv_strpos($format, ';') !== false) {
if (call_user_func(Zend_Locale_Math::$comp, $value, 0) < 0) {
$format = iconv_substr($format, iconv_strpos($format, ';') + 1);
print "\n3-Format3:'" . $format . "'";
} else {
$format = iconv_substr($format, 0, iconv_strpos($format, ';'));
print "\n3-Format4:'" . $format . "'";
}
}
} else {
print "\n3-Format5:'" . $format . "'";
// seperate negative format pattern when avaiable
if (iconv_strpos($format, ';') !== false) {
if (call_user_func(Zend_Locale_Math::$comp, $value, 0) < 0) {
$format = iconv_substr($format, iconv_strpos($format, ';') + 1);
print "\n3-Format6:'" . $format . "'";
} else {
$format = iconv_substr($format, 0, iconv_strpos($format, ';'));
print "\n3-Format7:'" . $format . "'";
}
}
if (strpos($format, '.')) {
print "\n4-Prec:'" . $options['precision'] . "'";
if (is_numeric($options['precision'])) {
$value = Zend_Locale_Math::round($value, $options['precision']);
print "\n4-Value1:'" . $value . "'";
//print "\nSet Pr:'".$value."'";
} else {
if (substr($format, strpos($format, '.') + 1, 3) == '###') {
$options['precision'] = null;
print "\n4-Value2";
} else {
$options['precision'] = strlen(substr($format, strpos($format, '.') + 1, strrpos($format, '0') - strpos($format, '.')));
print "\n4-Prec3:'" . $options['precision'] . "'";
$format = substr($format, 0, strpos($format, '.') + 1) . '###' . substr($format, strrpos($format, '0') + 1);
print "\n4-Format4:'" . $format . "'";
}
}
} else {
$value = Zend_Locale_Math::round($value, 0);
$options['precision'] = 0;
print "\n4-Value5:'" . $value . "'";
}
$value = Zend_Locale_Math::normalize($value);
print "\n5-Value:'" . $value . "'";
}
// get number parts
if (strlen($value) != strlen(Zend_Locale_Math::round($value, 0))) {
if ($options['precision'] === null) {
$precstr = iconv_substr($value, strlen(Zend_Locale_Math::round($value, 0)) + 1);
print "\n6-Prec1:'" . $precstr . "'";
} else {
$precstr = iconv_substr($value, strlen(Zend_Locale_Math::round($value, 0)) + 1, $options['precision']);
print "\n6-Prec2:'" . $precstr . "'";
if (iconv_strlen($precstr) < $options['precision']) {
$precstr = $precstr . str_pad("0", $options['precision'] - iconv_strlen($precstr), "0");
print "\n6-Prec3:'" . $precstr . "'";
}
}
} else {
print "\n6-Prec4";
if ($options['precision'] > 0) {
$precstr = str_pad("0", $options['precision'], "0");
print "\n6-Prec5:'" . $precstr . "'";
}
}
if ($options['precision'] === null) {
//.........这里部分代码省略.........