ZF2-569: Validate error with ,0 in I18n\Float
Description
The float validator works as expected with numbers endind with ,x where x>0, but with ,0 (or ,00 ,000 so on) it fails. With the following diff on FloatTest.php the test fails: 83c83
< $this->assertEquals(true, $this->validator->isValid('10,5'));
$this->assertEquals(true, $this->validator->isValid('10,0'));
That's because the following line 113 in Zend\I18n\Validator\Float.php returns 10 and not 10.0 $parsedFloat = $format->parse($value, NumberFormatter::TYPE_DOUBLE);
So the comparison in the line 128 if (strval($parsedFloat) !== $valueFiltered) {
fails because 10 !== 10.0
Comments
Posted by Philipp Dobrigkeit (pdobrigkeit) on 2012-09-19T10:13:20.000+0000
This is very annoying. Experienced it myself. Wrote a Unit-Test, but have no idea which would be the best way to fix it. Hoping for some feedback on github.
https://github.com/zendframework/zf2/pull/2386
Posted by Leandro Silva (lansoweb) on 2012-09-19T12:53:35.000+0000
I added the following code in Zend\I18n\Validator\Float.php and now all tests works as expected, including 125a126,130
I made a pull request with this proposed fix: https://github.com/zendframework/zf2/pull/2388
Posted by Leandro Silva (lansoweb) on 2012-09-20T09:31:51.000+0000
Fixed and already merged into master and develop: https://github.com/zendframework/zf2/pull/2388