0
<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 英镑

4

2 回答 2

1
echo count($Hours_Arr)*$Rate;

echo "£".round(count($Hours_Arr)*$Rate,2);
于 2013-07-08T02:12:30.607 回答
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 英镑

于 2013-07-08T02:16:35.117 回答