<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();
?>
With the above code... I've got a problem with:
echo count($Hours_Arr)*$Rate;
Which outputs:
14.94000005722
Which is not a valid point of pay. I wish for this to be an actual number format, but I have no idea how to get this integer to be:
£00.00
echo count($Hours_Arr)*$Rate;
can be
echo "£".round(count($Hours_Arr)*$Rate,2);
I'd personally go with a solution looking like this:
$Pay = count($Hours_Arr)*$Rate; // Calculate Pay
$Pay = round($Pay,2); // Round it to two Decimial Places
echo htmlentities("£").$Pay;
Mainly because of the readability when looking back over your code. This will output:
£14.94
The use of htmlentities
is to minimize the possible output of:
£14.94