I want to trim my decimal into something like 8.063
instead of the original which is 8.0638304611694E-9
. I have implemented a function for it but it doesn't work when there is E-9
in it. Which part should I modify??
public function setPrecision($number, $decimals = 0)
{
$negation = ($number < 0) ? (-1) : 1;
$coefficient = 10 ** $decimals;
return $negation * floor((string)(abs($number) * $coefficient)) / $coefficient;
}
EDIT
The current implementation gave me 0
when I try to call the function.
setPrecision(8.0638304611694E-9, 3); // 0