I want to add following numbers
$res = 0.000000002 + 0.000000002 + 0.000000002;
I got result like this
4.2E-8
can any one explain , how to get 0.000000006
thanks
I want to add following numbers
$res = 0.000000002 + 0.000000002 + 0.000000002;
I got result like this
4.2E-8
can any one explain , how to get 0.000000006
thanks
You should get the following result:
echo 0.000000002 + 0.000000002 + 0.000000002;
6.0E-9
Which means you haven't told us the truth.
One way to get 4.2E-8
is to add 0.00000002 + 0.00000002 + 0.000000002;
(I removed a zero from two of them).
Try
$res = 0.000000002 + 0.000000002 + 0.000000002;
printf("%0.9f",$res);
or
print(number_format($res,9));
Output
0.000000006
Please try this .
$res = 0.000000002 + 0.000000002 + 0.000000002;
echo number_format($res, 9, '.', '');die;
here 9 no is describe after dot how many digit you want to show.
$res = 0.0000000002 + 0.0000000002 + 0.0000000002;
echo exp2dec($res);
function exp2dec($number) {
preg_match('/(.*)E-(.*)/', str_replace(".", "", $number), $matches);
$num = "0.";
while ($matches[2] > 0) {
$num .= "0";
$matches[2]--;
}
return $num . $matches[1];
}
die;
Please try this.