<h2>Expected Pay <i>Between CutOff Period</i>:
<?php $Query = $Database->prepare("SELECT `Hours`,`BaseRate` FROM `hours`");
$Query->execute();
$Query->bind_result($HoursWorked, $Rate);
$Hours_Arr = array();
while ($Query->fetch()){
$Hours_Arr[] = $HoursWorked;
}
$Query->close();
echo round(count($Hours_Arr)*$Rate);
?>
</h2>
<h1>list Of Worked Hours</h1>
<?php
$Query = $Database->prepare("SELECT `DateWorked`,`StartTime`,`EndTime` FROM `hours`");
$Query->execute();
$Query->bind_result($DateWorked,$Started,$Finished);
while ($Query->fetch()){
echo "Date Worked: ".$DateWorked." Started At: ".$Started." Finished At: ".$Finished."<br>";
}
$Query->close();
?>
使用上面的代码......我遇到了问题:
echo count($Hours_Arr)*$Rate;
哪个输出:
14.94000005722
哪个不是有效的支付点。我希望这是一个实际的数字格式,但我不知道如何得到这个整数:
£00.00
答案 0 :(得分:1)
echo count($Hours_Arr)*$Rate;
可以
echo "£".round(count($Hours_Arr)*$Rate,2);
答案 1 :(得分:1)
我个人会选择这样的解决方案:
$Pay = count($Hours_Arr)*$Rate; // Calculate Pay
$Pay = round($Pay,2); // Round it to two Decimial Places
echo htmlentities("£").$Pay;
主要是因为回顾代码时的可读性。这将输出:
£14.94
htmlentities
的使用是为了尽量减少可能的输出:
一个£14.94