2013-07-08 62 views
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(); 
?> 

與上面的代碼...我有一個問題:這是工資回聲問題:

14.94000005722

:哪些輸出

echo count($Hours_Arr)*$Rate; 

不是有效的薪酬點。我想這是一個實際的數字格式,但我不知道如何得到這個整數是:

£00.00

+0

使用['sprinf() '](http://php.net/sprintf) – BlitZ

+1

或[FormatCurrency](http://php.net/manual/en/numberformatter.formatcurrency.php) – Orangepill

+0

@Orangepill t他可能應該真的更好';)' – BlitZ

回答

1
echo count($Hours_Arr)*$Rate; 

可以

echo "£".round(count($Hours_Arr)*$Rate,2); 
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