I have to sum values of an array. I have an array
$arr = array('0' => 87.85749999999999823, '1'=>1);
print_r(array_sum($arr));
And I am getting output as 88.8575, but I am expecting as 88.85749999999999823
Thanks for any help.
the float
is limited at 14 digit. if you need more accuracy, try the BC Math library
<?php
echo "<br/>float<br/>";
$arr = array('0' => 87.85749999999999823, '1'=>1);
print_r(($arr));
print_r(bcadd($arr[0], $arr[1], 20));
echo "<br/>BCMath<br/>";
$arr = array('0' => "87.85749999999999823", '1'=>"1");
print_r(($arr));
print_r(bcadd($arr[0], $arr[1], 20));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With