Created
April 18, 2020 15:27
-
-
Save Behinder/166bf67259268caa98675c849ecf0395 to your computer and use it in GitHub Desktop.
Increment and decrement float in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function incrementFLoat($float){ | |
echo $float."\n"; | |
$decimal = strlen(strrchr($float, '.')) -1; | |
$factor = pow(10,$decimal); | |
$incremented = (($factor * $float) + 1) / $factor; | |
return $incremented; | |
} | |
function decrementFLoat($float){ | |
// get amount of decimals | |
$decimal = strlen(strrchr($float, '.')) -1; | |
$factor = pow(10,$decimal); | |
$decremented = (($factor * $float) - 1) / $factor; | |
return $decremented; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment