I have a couple of PHP programs that don’t seem to add properly. The first one is a credit card number string and I’m adding each number to calculate the check digit. The second is a hotel reservation and calculates the total cost of a stay for each of 4 rooms. I get an extra ‘1’ added to the sum as it goes through the calculation. Here is the example of the Room Rates:
<?php
//$GTotal1 = 2507; This is the value for room 1
//$GTotal2 = 0; room 2 value
//$GTotal3 = 0; room 3 value
//$GTotal4 = 0; room 4 value
// $GTotalx = ($GTotal1 + $GTotal2 + $GTotal3 + $GTotal4);
$GTotalx = $GTotal1; // add room 1 total GTotalx now 2507
$GTotalx += $GTotal2; // room 2 total GTotalx now 2508
$GTotalx += $GTotal3; // room 3 total GTotalx now 2508
$GTotalx += $GTotal4; // room 4 total GTotalx now 2509
echo $GTotalx;
?>
Notice that the values for rooms 1-4 are 2507, 0, 0 and 0 entering this code or I can hard code it as commented out. Add this up and PHP gives me 2509. If I do it all on one line as commented out I still get 2509. One time it actually calculated correctly. HELP???
I’m new but this doesn’t make sense.
Thank you in advance.
Bill