Forum Moderators: coopster
function expn($value, $prec = 3, $base = 10, $prefix = '') {
$e = array('a', 'f', 'p', 'n', 'u', 'm', '', 'k', 'M', 'G', 'T', 'P', 'E');
$p = min(max(floor(log(abs($value), $base)), -6), 6);
return round((float)$value / pow($base, $p), $prec) . $prefx . $e[$p + 6];
}
I modified the base to 10 (from its original value of 1000), and then rounded your number to 6.
$mynum = 5.8987221219523E-05;
$myround = expn($mynum);
$myround = round($myround);
echo "Rounded: $myround";
Working with logarithms and exponents is for people younger and smarter than myself, so I'm at a loss to completely explain the function. Basically, you have to convert to a float before you can use round.