Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the logic for validating current value by step #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pkostadinov-2create
Copy link
Contributor

The previous code only works with integer steps, and does not account that modulo operator fails with 0.1 as the 2nd parameter.
The fmod also fails, by returning non-zero when 0 is expected.

Explanation:
https://stackoverflow.com/questions/3148937/compare-floats-in-php
https://stackoverflow.com/questions/32996034/fmod-returning-incorrect-result

The previous code only works with integer steps,  and does not account that modulo operator fails with `0.1` as the 2nd parameter.
The `fmod` also fails, by returning non-zero when `0` is expected.

Explanation:
https://stackoverflow.com/questions/3148937/compare-floats-in-php
https://stackoverflow.com/questions/32996034/fmod-returning-incorrect-result
Go back to basics - convert the number to string, and check if it contains decimal point. This seems to be the safest way to prove the number is integer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant