我有下面的代碼舍入我的數額到最近的美元:四捨五入到最接近的50美分
switch ($amazonResult['SalesRank']) {
case ($amazonResult['SalesRank'] < 1 || trim($amazonResult['SalesRank'])===''|| !isset($amazonResult['SalesRank']) || $amazonResult['SalesRank']=== null):
$Price=((float) $lowestAmazonPrice) * 0.05;
$payPrice = round($Price, 0); //to round the price up or down to the nearest $
break;
case ($amazonResult['SalesRank'] > 0 && $amazonResult['SalesRank'] <= 15000):
$Price=((float) $lowestAmazonPrice) * 0.20;
$payPrice = round($Price, 0); //to round the price up or down to the nearest $
break;
我明白,如果我使用圓形($價格,2);我會有2位小數,但有沒有辦法舍入到最接近的50美分?
謝謝,這確實起作用。 – Jim 2012-07-27 17:52:02