Skip to content

Instantly share code, notes, and snippets.

@rakkang
Created February 16, 2016 02:48
Show Gist options
  • Save rakkang/02e528f5a3709329ddd5 to your computer and use it in GitHub Desktop.
Save rakkang/02e528f5a3709329ddd5 to your computer and use it in GitHub Desktop.
Get the availble number count after the dot in a float number!
<?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