ZF2-569: Validate error with ,0 in I18n\Float

Issue Type: Bug Created: 2012-09-18T13:05:44.000+0000 Last Updated: 2012-09-20T09:31:51.000+0000 Status: Resolved Fix version(s): - 2.0.0 (06/Sep/12)

Reporter: Leandro Silva (lansoweb) Assignee: Leandro Silva (lansoweb) Tags: - Zend\I18n

  • locale
  • validating

Related issues: Attachments:


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


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.

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

while (strpos($valueFiltered,'.') !== false && ($valueFiltered[strlen($valueFiltered)-1] == '0' || $valueFiltered[strlen($valueFiltered)-1] == '.')) { $valueFiltered = substr($valueFiltered, 0, strlen($valueFiltered)-1); }

I made a pull request with this proposed fix:

Posted by Leandro Silva (lansoweb) on 2012-09-20T09:31:51.000+0000

Fixed and already merged into master and develop:

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.