本文整理汇总了PHP中Zend_Locale_Format::getNumber方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Locale_Format::getNumber方法的具体用法?PHP Zend_Locale_Format::getNumber怎么用?PHP Zend_Locale_Format::getNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Locale_Format
的用法示例。
在下文中一共展示了Zend_Locale_Format::getNumber方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _getValueToSaveFromPostData
protected function _getValueToSaveFromPostData($postData)
{
$ret = parent::_getValueToSaveFromPostData($postData);
$l = $this->_floatValidator->getLocale();
$ret = Zend_Locale_Format::getNumber($ret, array('locale' => $l));
return $ret;
}
示例2: dataValue
/**
* extracts the
* @return type
*/
public function dataValue()
{
require_once THIRDPARTY_PATH . "/Zend/Locale/Format.php";
$locale = new Zend_Locale(i18n::get_locale());
$number = Zend_Locale_Format::getNumber($this->value, array('locale' => $locale));
return $number;
}
示例3: dataValue
/**
* Extracts the number value from the localised string value
*
* @return string number value
*/
public function dataValue()
{
require_once "Zend/Locale/Format.php";
if (!$this->isNumeric()) {
return 0;
}
$locale = new Zend_Locale($this->getLocale());
$number = Zend_Locale_Format::getNumber($this->clean($this->value), array('locale' => $locale));
return $number;
}
示例4: Value
/**
* @return string
* @throws Zend_Locale_Exception
*/
public function Value()
{
if (!$this->isNumeric()) {
return '0%';
}
require_once "Zend/Locale/Format.php";
$locale = new Zend_Locale($this->getLocale());
// convert from the stored format to a real number so we can multiply
$number = Zend_Locale_Format::getNumber($this->clean($this->value), array('locale' => $locale));
$number *= 100.0;
// convert back to string
$val = Zend_Locale_Format::toNumber($number, array('locale' => $locale));
return $val . '%';
}
示例5: testGetNumber
/**
* test getNumber
* expected integer
*/
public function testGetNumber()
{
$this->assertEquals(Zend_Locale_Format::getNumber(0), 0, "value 0 expected");
$this->assertEquals(Zend_Locale_Format::getNumber(-1234567), -1234567, "value -1234567 expected");
$this->assertEquals(Zend_Locale_Format::getNumber(1234567), 1234567, "value 1234567 expected");
$this->assertEquals(Zend_Locale_Format::getNumber(0.1234567), 0.1234567, "value 0.1234567 expected");
$this->assertEquals(Zend_Locale_Format::getNumber(-1234567.12345), -1234567.12345, "value -1234567.12345 expected");
$this->assertEquals(Zend_Locale_Format::getNumber(1234567.12345), 1234567.12345, "value 1234567.12345 expected");
$this->assertEquals(Zend_Locale_Format::getNumber('0', 'de'), 0, "value 0 expected");
$this->assertEquals(Zend_Locale_Format::getNumber('-1234567', 'de'), -1234567, "value -1234567 expected");
$this->assertEquals(Zend_Locale_Format::getNumber('1234567', 'de'), 1234567, "value 1234567 expected");
$this->assertEquals(Zend_Locale_Format::getNumber('0,1234567', 'de'), 0.1234567, "value 0.1234567 expected");
$this->assertEquals(Zend_Locale_Format::getNumber('-1.234.567,12345', 'de'), -1234567.12345, "value -1234567.12345 expected");
$this->assertEquals(Zend_Locale_Format::getNumber('1.234.567,12345', 'de'), 1234567.12345, "value 1234567.12345 expected");
$this->assertEquals(Zend_Locale_Format::getNumber('0', 'de_AT'), 0, "value 0 expected");
$this->assertEquals(Zend_Locale_Format::getNumber('-1234567', 'de_AT'), -1234567, "value -1234567 expected");
$this->assertEquals(Zend_Locale_Format::getNumber('1.234.567', 'de_AT'), 1234567, "value 1234567 expected");
$this->assertEquals(Zend_Locale_Format::getNumber('0,1234567', 'de_AT'), 0.1234567, "value 0.1234567 expected");
$this->assertEquals(Zend_Locale_Format::getNumber('-1.234.567,12345', 'de_AT'), -1234567.12345, "value -1234567.12345 expected");
$this->assertEquals(Zend_Locale_Format::getNumber('1.234.567,12345', 'de_AT'), 1234567.12345, "value 1234567.12345 expected");
}
示例6: testGetNumber
/**
* test getNumber
* expected integer
*/
public function testGetNumber()
{
$this->assertEquals( 0, Zend_Locale_Format::getNumber( 0) );
$this->assertEquals(-1234567, Zend_Locale_Format::getNumber(-1234567) );
$this->assertEquals( 1234567, Zend_Locale_Format::getNumber( 1234567) );
$this->assertEquals( 0.1234567, Zend_Locale_Format::getNumber( 0.1234567));
$this->assertEquals(-1234567.12345, Zend_Locale_Format::getNumber(-1234567.12345) );
$this->assertEquals( 1234567.12345, Zend_Locale_Format::getNumber(1234567.12345) );
$options = array('locale' => 'de');
$this->assertEquals( 0, Zend_Locale_Format::getNumber( '0', $options));
$this->assertEquals(-1234567, Zend_Locale_Format::getNumber( '-1234567', $options));
$this->assertEquals( 1234567, Zend_Locale_Format::getNumber( '1234567', $options));
$this->assertEquals( 0.1234567, Zend_Locale_Format::getNumber(' 0,1234567', $options));
$this->assertEquals(-1234567.12345, Zend_Locale_Format::getNumber('-1.234.567,12345', $options));
$this->assertEquals( 1234567.12345, Zend_Locale_Format::getNumber(' 1.234.567,12345', $options));
$options = array('locale' => 'de_AT');
$this->assertEquals( 0, Zend_Locale_Format::getNumber( '0', $options));
$this->assertEquals(-1234567, Zend_Locale_Format::getNumber( '-1234567', $options));
$this->assertEquals( 1234567, Zend_Locale_Format::getNumber( '1.234.567', $options));
$this->assertEquals( 0.1234567, Zend_Locale_Format::getNumber( '0,1234567', $options));
$this->assertEquals(-1234567.12345, Zend_Locale_Format::getNumber('-1.234.567,12345', $options));
$this->assertEquals( 1234567.12345, Zend_Locale_Format::getNumber( '1.234.567,12345', $options));
}
示例7: setValue
/**
* Set a new value
*
* @param $value mixed - Value as string, integer, real or float
* @param $type type - OPTIONAL a Zend_Measure_Area Type
* @param $locale locale - OPTIONAL a Zend_Locale Type
* @throws Zend_Measure_Exception
*/
public function setValue($value, $type, $locale = false)
{
if (empty($locale)) {
$locale = $this->_Locale;
}
$value = Zend_Locale_Format::getNumber($value, $locale);
if (empty(self::$_UNITS[$type])) {
self::throwException('unknown type of area:' . $type);
}
parent::setValue($value, $type, $locale);
parent::setType($type);
}
示例8: caConvertLocaleSpecificFloat
/**
* Takes locale-formatted float (eg. 54,33) and converts it to the "standard"
* format needed for calculations (eg 54.33)
*
* @param string $ps_value The value to convert
* @param string $ps_locale The locale of the value
* @return float The converted value
*/
function caConvertLocaleSpecificFloat($ps_value, $ps_locale = "en_US")
{
try {
return Zend_Locale_Format::getNumber($ps_value, array('locale' => $ps_locale));
} catch (Zend_Locale_Exception $e) {
// happens when you enter 54.33 but 54,33 is expected in the current locale
return floatval($ps_value);
}
}
示例9: setValue
/**
* Set a new value
*
* @param $value mixed - Value as string, integer, real or float
* @param $type type - OPTIONAL a Zend_Measure_Number Type
* @param $locale locale - OPTIONAL a Zend_Locale Type
* @throws Zend_Measure_Exception
*/
public function setValue($value, $type, $locale = false)
{
if (empty($locale)) {
$locale = $this->_Locale;
}
if (empty(self::$_UNITS[$type])) {
self::throwException('unknown type of number:' . $type);
}
switch ($type) {
case 'Number::BINARY':
preg_match('/[01]+/', $value, $ergebnis);
$value = $ergebnis[0];
break;
case 'Number::TERNARY':
preg_match('/[012]+/', $value, $ergebnis);
$value = $ergebnis[0];
break;
case 'Number::QUATERNARY':
preg_match('/[0123]+/', $value, $ergebnis);
$value = $ergebnis[0];
break;
case 'Number::QUINARY':
preg_match('/[01234]+/', $value, $ergebnis);
$value = $ergebnis[0];
break;
case 'Number::SENARY':
preg_match('/[012345]+/', $value, $ergebnis);
$value = $ergebnis[0];
break;
case 'Number::SEPTENARY':
preg_match('/[0123456]+/', $value, $ergebnis);
$value = $ergebnis[0];
break;
case 'Number::OCTAL':
preg_match('/[01234567]+/', $value, $ergebnis);
$value = $ergebnis[0];
break;
case 'Number::NONARY':
preg_match('/[012345678]+/', $value, $ergebnis);
$value = $ergebnis[0];
break;
case 'Number::DUODECIMAL':
preg_match('/[0123456789AB]+/', strtoupper($value), $ergebnis);
$value = $ergebnis[0];
break;
case 'Number::HEXADECIMAL':
preg_match('/[0123456789ABCDEF]+/', strtoupper($value), $ergebnis);
$value = $ergebnis[0];
break;
case 'Number::ROMAN':
preg_match('/[IVXLCDM_]+/', strtoupper($value), $ergebnis);
$value = $ergebnis[0];
break;
default:
$value = Zend_Locale_Format::getNumber($value, $locale);
if (bccomp($value, 0) < 0) {
$value = bcsqrt(bcpow($value, 2));
}
break;
}
parent::setValue($value, $type, $locale);
parent::setType($type);
}
示例10: testGetNumberWithZeroPrecision
/**
* @group ZF-9160
*/
public function testGetNumberWithZeroPrecision()
{
$this->assertEquals(1234, Zend_Locale_Format::getNumber('1234.567', array('locale' => 'en_US', 'precision' => 0)));
}
示例11: setValue
/**
* Set a new value
*
* @param $value mixed - Value as string, integer, real or float
* @param $type type - OPTIONAL a Zend_Measure_Torque Type
* @param $locale locale - OPTIONAL a Zend_Locale Type
* @throws Zend_Measure_Exception
*/
public function setValue($value, $type, $locale = false)
{
if (empty($locale)) {
$locale = $this->_Locale;
}
try {
$value = Zend_Locale_Format::getNumber($value, $locale);
} catch (Exception $e) {
throw Zend::exception('Zend_Measure_Exception', $e->getMessage());
}
if (empty(self::$_UNITS[$type])) {
throw Zend::exception('Zend_Measure_Exception', 'unknown type of torque:' . $type);
}
parent::setValue($value, $type, $locale);
parent::setType($type);
}
示例12: setValue
/**
* Set a new value
*
* @param integer|string $value Value as string, integer, real or float
* @param string $type OPTIONAL A Zend_Measure_Flow_Mass Type
* @param string|Zend_Locale $locale OPTIONAL Locale for parsing numbers
* @throws Zend_Measure_Exception
*/
public function setValue($value, $type = null, $locale = null)
{
if ($locale === null) {
$locale = $this->_Locale;
}
if (!($locale = Zend_Locale::isLocale($locale, true))) {
throw new Zend_Measure_Exception("language ({$locale}) is a unknown language");
}
if ($type === null) {
$type = self::STANDARD;
}
try {
$value = Zend_Locale_Format::getNumber($value, $locale);
} catch (Exception $e) {
throw new Zend_Measure_Exception($e->getMessage());
}
if (empty(self::$_UNITS[$type])) {
throw new Zend_Measure_Exception("type ({$type}) is a unknown flow mass");
}
parent::setValue($value, $type, $locale);
parent::setType($type);
}
示例13: _localizeNumber
protected function _localizeNumber($number, $options = array())
{
$options = Mage::helper('currencymanager')->getOptions($options, true, $this->getCurrencyCode());
if ($options['display'] == Zend_Currency::NO_SYMBOL) {
// in Zend_Currency toCurrency() function
// are stripped unbreakable spaces only for currency without Currency Symbol
return $number;
} else {
$locale = Mage::app()->getLocale()->getLocaleCode();
$format = Zend_Locale_Data::getContent($locale, 'decimalnumber');
$numberOptions = array('locale' => $locale, 'number_format' => $format, 'precision' => 0);
$number = Zend_Locale_Format::getNumber($number, $numberOptions);
return Zend_Locale_Format::toNumber($number, $numberOptions);
}
}
示例14: testRegionSeperatedPositive
/**
* test positive seperation language locale
* expected integer
*/
public function testRegionSeperatedPositive()
{
$value = Zend_Locale_Format::getNumber('1.234.567,12345', 'de_AT');
$this->assertEquals($value, 1234567.12345, "value 1234567.12345 expected");
}
示例15: getNumber
/**
* Returns the normalized number from a localized one
* Parsing depends on the Formatter locale
* @param String $input Formatted String
* @param Integer $digits Precision
* @return String normalized number of Boolean false
* if $input is not a valid formatted number.
*/
public function getNumber($input, $digits = null)
{
try {
return Zend_Locale_Format::getNumber($input, array('locale' => $this->zendLocale, 'precision' => $digits));
} catch (Zend_Locale_Exception $e) {
// The string is not a valid formatted number.
return false;
}
}