Is there a straightforward way of determining the number of decimal places in a(n) integer/double value in PHP? (that is, without using explode)
Here's a function that takes into account trailing zeroes:
function get_precision($value) {
if (!is_numeric($value)) { return false; }
$decimal = $value - floor($value); //get the decimal portion of the number
if ($decimal == 0) { return 0; } //if it's a whole number
$precision = strlen($decimal) - 2; //-2 to account for "0."
return $precision;
}