本文整理汇总了PHP中Zend_Locale_Format::isFloat方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Locale_Format::isFloat方法的具体用法?PHP Zend_Locale_Format::isFloat怎么用?PHP Zend_Locale_Format::isFloat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Locale_Format
的用法示例。
在下文中一共展示了Zend_Locale_Format::isFloat方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isValid
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is a floating-point value
*
* @todo http://framework.zend.com/issues/browse/ZF-2895
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
if (!Zend_Locale_Format::isFloat($valueString, $this->_options)) {
$this->_error();
return false;
}
return true;
}
示例2: isValid
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is a floating-point value
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
$valueString = (string) $value;
$this->_setValue($valueString);
try {
if (!Zend_Locale_Format::isFloat($value, array('locale' => $this->_locale))) {
$this->_error();
return false;
}
} catch (Zend_Locale_Exception $e) {
$this->_error();
return false;
}
return true;
}
示例3: isValid
public function isValid($value)
{
if (!is_string($value) && !is_int($value) && !is_float($value)) {
$this->_error(self::INVALID);
return false;
}
if (is_float($value)) {
return true;
}
$value = str_replace('.', ',', $value);
$this->_setValue($value);
try {
if (!Zend_Locale_Format::isFloat($value, array('locale' => 'pl'))) {
$this->_error(self::NOT_FLOAT);
return false;
}
} catch (Zend_Locale_Exception $e) {
$this->_error(self::NOT_FLOAT);
return false;
}
return true;
}
示例4: testIsFloat
/**
* test isFloat
* expected boolean
*/
public function testIsFloat()
{
$this->assertTrue( Zend_Locale_Format::isFloat('-1.234.567,12345', array('locale' => 'de_AT')));
$this->assertFalse(Zend_Locale_Format::isFloat('textwithoutnumber', array('locale' => 'de_AT')));
}
示例5: testShortNotation
public function testShortNotation()
{
$this->assertEquals(0.12345, Zend_Locale_Format::getNumber(0.12345));
$options = array('locale' => 'de');
$this->assertEquals(0.12345, Zend_Locale_Format::getNumber(',12345', $options));
$options = array('locale' => 'de_AT');
$this->assertEquals(0.12345, Zend_Locale_Format::getNumber(',12345', $options));
$this->assertEquals('0,75', Zend_Locale_Format::toNumber(0.75, array('locale' => 'de_DE', 'precision' => 2)));
$this->assertTrue(Zend_Locale_Format::isNumber(',12345', array('locale' => 'de_AT')));
$this->assertEquals(0.12345, Zend_Locale_Format::getFloat(0.12345));
$options = array('locale' => 'de');
$this->assertEquals(0.12345, Zend_Locale_Format::getFloat(',12345', $options));
$options = array('locale' => 'de_AT');
$this->assertEquals(0.12345, Zend_Locale_Format::getFloat(',12345', $options));
$options = array('locale' => 'de_AT');
$this->assertEquals('0,12345', Zend_Locale_Format::toFloat(0.12345, $options));
$options = array('locale' => 'ar_QA');
$this->assertEquals('0,12345', Zend_Locale_Format::toFloat(0.12345, $options));
$this->assertTrue(Zend_Locale_Format::isFloat(',12345', array('locale' => 'de_AT')));
$this->assertEquals(0, Zend_Locale_Format::getInteger(0.1234567));
$options = array('locale' => 'de');
$this->assertEquals(0, Zend_Locale_Format::getInteger(',12345', $options));
$options = array('locale' => 'de_AT');
$this->assertEquals(0, Zend_Locale_Format::getInteger(',12345', $options));
$this->assertEquals('0', Zend_Locale_Format::toInteger(0.123, array('locale' => 'de')));
$options = array('locale' => 'de_AT');
$this->assertEquals('0', Zend_Locale_Format::toInteger(0.12345, $options));
$this->assertFalse(Zend_Locale_Format::isInteger(',12345', array('locale' => 'de_AT')));
$options = array('locale' => 'de_AT');
$this->assertEquals('0,567', Zend_Locale_Format::toNumber(0.5669999999999999, $options));
}
示例6: testIsFloat
/**
* test isFloat
* expected boolean
*/
public function testIsFloat()
{
$this->assertEquals(Zend_Locale_Format::isFloat('-1.234.567,12345', array('locale' => 'de_AT')), true, "true expected");
$this->assertEquals(Zend_Locale_Format::isFloat('textwithoutnumber', array('locale' => 'de_AT')), false, "false expected");
}
示例7: isValid
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is a floating-point value
*
* @param string $value
* @return boolean
*/
public function isValid($value)
{
if (!is_string($value) && !is_int($value) && !is_float($value)) {
$this->_error(self::INVALID);
return false;
}
$this->_setValue($value);
if ($this->_locale === null) {
$locale = localeconv();
$valueFiltered = str_replace($locale['thousands_sep'], '', (string) $value);
$valueFiltered = str_replace($locale['decimal_point'], '.', $valueFiltered);
if (strval(floatval($valueFiltered)) != $valueFiltered) {
$this->_error(self::NOT_FLOAT);
return false;
}
} else {
try {
if (!Zend_Locale_Format::isFloat($value, array('locale' => 'en')) && !Zend_Locale_Format::isFloat($value, array('locale' => $this->_locale))) {
$this->_error(self::NOT_FLOAT);
return false;
}
} catch (Zend_Locale_Exception $e) {
$this->_error(self::NOT_FLOAT);
return false;
}
}
return true;
}
示例8: testIsFloatFailed
/**
* test if isNumberFailed
* expected boolean
*/
public function testIsFloatFailed()
{
$value = Zend_Locale_Format::isFloat('textwithoutnumber', 'de_AT');
$this->assertEquals($value, FALSE, "FALSE expected");
}
示例9: filter
/**
* Defined by Zend_Filter_Interface
*
* Normalizes the given input
*
* @param string $value Value to normalized
* @return string|array The normalized value
*/
public function filter($value)
{
if ($this->_options['date_format'] === null && strpos($value, ':') !== false) {
// Special case, no date format specified, detect time input
return Zend_Locale_Format::getTime($value, $this->_options);
} else {
if (Zend_Locale_Format::checkDateFormat($value, $this->_options)) {
// Detect date or time input
return Zend_Locale_Format::getDate($value, $this->_options);
} else {
if ($this->_options['precision'] === 0 && Zend_Locale_Format::isInteger($value, $this->_options)) {
// Detect integer
return Zend_Locale_Format::getInteger($value, $this->_options);
} else {
if ($this->_options['precision'] === null && Zend_Locale_Format::isFloat($value, $this->_options)) {
// Detect float
return Zend_Locale_Format::getFloat($value, $this->_options);
} else {
if (Zend_Locale_Format::isNumber($value, $this->_options)) {
// Detect all other numbers
return Zend_Locale_Format::getNumber($value, $this->_options);
}
}
}
}
}
return $value;
}