/** * 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; }
/** * 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; }
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; }
/** * 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'))); }
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)); }
/** * 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"); }
/** * 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; }
/** * test if isNumberFailed * expected boolean */ public function testIsFloatFailed() { $value = Zend_Locale_Format::isFloat('textwithoutnumber', 'de_AT'); $this->assertEquals($value, FALSE, "FALSE expected"); }
/** * 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; }