Skip to content

Instantly share code, notes, and snippets.

@Behinder
Created April 18, 2020 15:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Behinder/166bf67259268caa98675c849ecf0395 to your computer and use it in GitHub Desktop.
Save Behinder/166bf67259268caa98675c849ecf0395 to your computer and use it in GitHub Desktop.
Increment and decrement float in PHP
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