Created
February 16, 2016 02:48
-
-
Save rakkang/02e528f5a3709329ddd5 to your computer and use it in GitHub Desktop.
Get the availble number count after the dot in a float number!
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
<?php | |
/** | |
* 获取浮点数后的有效小数位数 | |
*/ | |
function getFloatLenAfterDot($numbric) | |
{ | |
echo "Orinial: " . $numbric . "\n"; | |
$arr = explode(".", $numbric); | |
print_r($arr); | |
if ($arr && count($arr) == 2) { | |
if (strpos($arr[1], "0E") === false) { | |
return strlen($arr[1]); | |
} else { | |
return explode("-", $arr[1])[1]; | |
} | |
} | |
return false; | |
} | |
echo getFloatLenAfterDot(0.022202) . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment