compare sum of big array values give wrong result PHP

Viewed 30

i want to compare the sum of array values with number 100.00 With few array values it execute right statement but if i compare with long array values it executes wrong statement. here is code:

$ratio = array(49,25.50,25.50);
$ratio_sum = array_sum($ratio);
if(ratio_sum == 100.00)
        {
            echo 'equal to 100';
        }
        else
        {
            echo 'not equal to 100';
        }

this execute right statement but when i try with following array which have so many values then it execute wrong statement

$ratio = array(37.025,0.15,0.250,0.300,0.150,0.250,0.125,1.50,2.25,0.350,7.00,22.50,15.00,1.00,0.500,10.750,0.500,0.100,0.300);
$ratio_sum = array_sum($ratio);
if(ratio_sum == 100.00)
        {
            echo 'equal to 100';
        }
        else
        {
            echo 'not equal to 100';
        }

this code answer is : not equal to 100 but i calulate this long array value in calculator manually and its sum is 100

0 Answers
Related