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
)
If you want readability for the benefit of other devs, locale safe, use:
function countDecimalPlacesUsingStrrpos($stringValue){
$locale_info = localeconv();
$pos = strrpos($stringValue, $locale_info['decimal_point']);
if ($pos !== false) {
return strlen($stringValue) - ($pos + 1);
}
return 0;
}
see localeconv