我创建了3个功能来计算收入,人力成本和其他费用。但是当我试图获得净收入($ ni)时,我的代码返回零,尽管我的变量有一个值参见下面的代码;
$revenue = revenue($project, $period);
$manpowerCost = manpowerCost($project, $period);
$otherCharges = otherCharges($project, $period);
$ni = $revenue - $manpowerCost - $otherCharges;
我的代码在这里出了什么问题?
由于
答案 0 :(得分:1)
请为每个号码使用intval
或floatval
,例如
$ni = intval($revenue) - intval($manpowerCost) - intval($otherCharges);
或
$ni = floatval($revenue) - floatval($manpowerCost) - floatval($otherCharges);
你会得到答案。
答案 1 :(得分:0)
根据您的功能返回,您可以尝试
$revenue = floatval(revenue($project, $period));
$manpowerCost = floatval(manpowerCost($project, $period));
$otherCharges = floatval(otherCharges($project, $period));
$ni = $revenue - $manpowerCost - $otherCharges;
有关详细信息,请参阅http://www.php.net/manual/en/language.types.type-juggling.php。