/** * Returns true if and only if $value is a valid integer * * @param string|integer $value * @return boolean */ public function isValid($value) { if (!is_string($value) && !is_int($value) && !is_float($value)) { $this->error(self::INVALID); return false; } if (is_int($value)) { return true; } $this->setValue($value); if ($this->_locale === null) { $locale = localeconv(); $valueFiltered = str_replace($locale['decimal_point'], '.', $value); $valueFiltered = str_replace($locale['thousands_sep'], '', $valueFiltered); if (strval(intval($valueFiltered)) != $valueFiltered) { $this->error(self::NOT_INT); return false; } } else { try { if (!\Zend\Locale\Format::isInteger($value, array('locale' => $this->_locale))) { $this->error(self::NOT_INT); return false; } } catch (\Zend\Locale\Exception $e) { $this->error(self::NOT_INT); return false; } } return true; }
public function testShortNotation() { $this->assertEquals(0.12345, Format::getNumber(0.12345)); $options = array('locale' => 'de'); $this->assertEquals(0.12345, Format::getNumber(',12345', $options)); $options = array('locale' => 'de_AT'); $this->assertEquals(0.12345, Format::getNumber(',12345', $options)); $this->assertEquals('0,75', Format::toNumber(0.75, array('locale' => 'de_DE', 'precision' => 2))); $this->assertTrue(Format::isNumber(',12345', array('locale' => 'de_AT'))); $this->assertEquals(0.12345, Format::getFloat(0.12345)); $options = array('locale' => 'de'); $this->assertEquals(0.12345, Format::getFloat(',12345', $options)); $options = array('locale' => 'de_AT'); $this->assertEquals(0.12345, Format::getFloat(',12345', $options)); $options = array('locale' => 'de_AT'); $this->assertEquals('0,12345', Format::toFloat(0.12345, $options)); $options = array('locale' => 'ar_QA'); $this->assertEquals('0,12345', Format::toFloat(0.12345, $options)); $this->assertTrue(Format::isFloat(',12345', array('locale' => 'de_AT'))); $this->assertEquals(0, Format::getInteger(0.1234567)); $options = array('locale' => 'de'); $this->assertEquals(0, Format::getInteger(',12345', $options)); $options = array('locale' => 'de_AT'); $this->assertEquals(0, Format::getInteger(',12345', $options)); $this->assertEquals('0', Format::toInteger(0.123, array('locale' => 'de'))); $options = array('locale' => 'de_AT'); $this->assertEquals('0', Format::toInteger(0.12345, $options)); $this->assertFalse(Format::isInteger(',12345', array('locale' => 'de_AT'))); $options = array('locale' => 'de_AT'); $this->assertEquals('0,567', Format::toNumber(0.5669999999999999, $options)); }