Ctshaw
Ctshaw

Reputation: 217

PHP division resulting in zero

I am trying to do some division in my PHP program and for some reason the result is zero when it should not be. Below is my code:

print("Historic Total: '$histoicTotal' Valid weeks: '$numValidWeeks'");

$historicAvg = $historicTotal/$numValidWeeks;

print(($historicTotal)/($numValidWeeks));
print(30/1);

$totalAvg = (($historicAvg + $avg)/2);
print("Havg = '$historicAvg' + Avg '$avg' "); 
print($totalAvg);

The output is Historic Total: '30' Valid weeks: '1'030Havg = '0' + Avg '' 0

Upvotes: 1

Views: 56

Answers (1)

Zbynek Vyskovsky - kvr000
Zbynek Vyskovsky - kvr000

Reputation: 18825

There is a typo: $histoicTotal is missing "r" in the middle. Compare to variable name on the second line: $historicTotal.

Upvotes: 2

Related Questions