Last active
November 5, 2017 16:38
-
-
Save s3b4stian/774f063b82d361a226a413b014299d7f to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Convert number given as string to the proper type (int or float). | |
* https://secure.php.net/manual/en/language.types.type-juggling.php | |
* | |
* @param string $string Number as string ex '1.0', '0.9' etc | |
* @return int|float | |
*/ | |
function strtonum(string $string) | |
{ | |
if (fmod((float)$string, 1.0) === 0.0){ | |
return (int) $string; | |
} | |
return (float) $string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment