Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.

Proposed fix for ZF2-569 validating float with trailing 0's (10.0, 10.10)#2388

Closed
Lansoweb wants to merge 5 commits into
zendframework:masterfrom
Lansoweb:master
Closed

Proposed fix for ZF2-569 validating float with trailing 0's (10.0, 10.10)#2388
Lansoweb wants to merge 5 commits into
zendframework:masterfrom
Lansoweb:master

Conversation

@Lansoweb
Copy link
Copy Markdown
Contributor

The actual validation fails with trailing zeros inside decimal part like 10.0 or 10.10. This happens because NumberFormatter->parse('10.0') returns 10 and not 10.0 and the valueFiltered remains '10.0'.

This proposed fix removes all trailing 0 (and ending . if any) from valueFiltered before comparison.

The problem is described in http://framework.zend.com/issues/browse/ZF2-569

@pdobrigkeit
Copy link
Copy Markdown
Contributor

Very nice. I was playing around with the idea to do a

$valueFiltered = preg_replace('/[0]*$/', $valueFiltered);

But that gave trouble when the value was actually 0 and now it seems I don't have to think anymore ;)

weierophinney added a commit that referenced this pull request Sep 19, 2012
- trailing whitespace
- break conditional into multiple lines for readability
- whitespace around operators
weierophinney added a commit that referenced this pull request Sep 19, 2012
Forward port #2388

Conflicts:
	library/Zend/I18n/Validator/Float.php
	tests/ZendTest/I18n/Validator/FloatTest.php
@ghost ghost assigned weierophinney Sep 19, 2012
weierophinney added a commit to zendframework/zend-i18n that referenced this pull request May 15, 2015
- trailing whitespace
- break conditional into multiple lines for readability
- whitespace around operators
weierophinney added a commit to zendframework/zend-i18n that referenced this pull request May 15, 2015
weierophinney added a commit to zendframework/zend-i18n that referenced this pull request May 15, 2015
Forward port zendframework/zendframework#2388

Conflicts:
	library/Zend/I18n/Validator/Float.php
	tests/ZendTest/I18n/Validator/FloatTest.php
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants