基本php表单帮助(货币显示)

基本php表单帮助(货币显示),php,forms,currency,rounding,Php,Forms,Currency,Rounding,你们昨天帮了大忙。不过我还是有点困惑 我想将最右边一栏中的数字四舍五入到最接近的美元: 该表的代码如下所示: 我想将$offer[1,2,3,4,5,6,7]CalcSavingsan四舍五入,怎么做 <table width="100%;" border="0" cellspacing="0" cellpadding="0"class="credit_table2" > <tr class="credit_table2_brd"> <td

你们昨天帮了大忙。不过我还是有点困惑

我想将最右边一栏中的数字四舍五入到最接近的美元:

该表的代码如下所示:

我想将$offer[1,2,3,4,5,6,7]CalcSavingsan四舍五入,怎么做

 <table width="100%;" border="0" cellspacing="0" cellpadding="0"class="credit_table2" >

    <tr class="credit_table2_brd">
     <td class="credit_table2_brd_lbl" width="100px;">Services:</td>
<td class="credit_table2_brd_lbl" width="120px;">Our Ratings:</td>
<td class="credit_table2_brd_lbl" width="155px;">Monthly VoIP Bill:</td>
<td class="credit_table2_brd_lbl" width="155px;">Annual Savings:</td>

   </tr>  

   <?php

 $offer1price="24.99";
 $offer2price="20.00";
 $offer3price="21.95";
 $offer4price="23.95";
 $offer5price="19.95";
 $offer6price="23.97";
 $offer7price="24.99";

 $offer1calcsavings= $monthlybill - $offer1price;
 $offer2calcsavings= $monthlybill - $offer2price;
 $offer3calcsavings= $monthlybill - $offer3price;
 $offer4calcsavings= $monthlybill - $offer4price;
 $offer5calcsavings= $monthlybill - $offer5price;
 $offer6calcsavings= $monthlybill - $offer6price;
 $offer7calcsavings= $monthlybill - $offer7price;

 $monthybill="monthlybill";

 $offer1calcsavingsann= $offer1calcsavings * 12;
 $offer2calcsavingsann= $offer2calcsavings * 12;
 $offer3calcsavingsann= $offer3calcsavings * 12;
 $offer4calcsavingsann= $offer4calcsavings * 12;
 $offer5calcsavingsann= $offer5calcsavings * 12;
 $offer6calcsavingsann= $offer6calcsavings * 12;
 $offer7calcsavingsann= $offer7calcsavings * 12;

   $re=1;
   $offer ='offer'.$re.'name';
 $offername= ${$offer};
   while($offername!=""){
$offerlo ='offer'.$re.'logo';
$offerlogo=${$offerlo};
$offerli ='offer'.$re.'link';
$offerlink=${$offerli};
$offeran ='offer'.$re.'anchor';
$offeranchor=${$offeran};
$offerst ='offer'.$re.'star1';
$offerstar=${$offerst};
$offerbot='offer'.$re.'bottomline';
$offerbottomline=${$offerbot};
$offerca ='offer'.$re.'calcsavings';
$offercalcsavings=${$offerca};
    $offerpr ='offer'.$re.'price';
$offerprice=${$offerpr};
$offersavann ='offer'.$re.'calcsavingsann';
$offercalcsavingsann=${$offersavann};

echo '<tr >
     <td >
 <a href="'.$offerlink.'" target="blank"><img src="http://www.nextadvisor.com'.$offerlogo.'" alt="'.$offername.'" />
 </a>
 </td>
<td ><span class="rating_text">Rating:</span>
 <span class="star_rating1">
 <img src="http://www.nextadvisor.com'.$offerstar.'" alt="" />
 </span>
 <br />
  <div style="margin-top:5px; color:#0000FF;">
 <a href="'.$offerlink.'" target="blank">Go to Site</a>
 <span style="margin:0px 7px 0px 7px;">|</span><a href="'.$offeranchor.'">Review</a>     

 </div> </td>
       <td >$'.$offerprice.'</td>
     <td >$'.$offercalcsavingsann.'</td>


   </tr>';
   $re=$re+1;
   $offer ='offer'.$re.'name';
 $offername= ${$offer};

   }



   ?>



 </table>

服务:
我们的评级:
每月VoIP账单:
每年节省:

是否要向上/向下/截断到最接近的美元

以下是您可以使用的一些建议功能:

四舍五入

格式化/截断


格雷普塞德的答案是好的;我唯一要补充的是,例如,您可以使用输出$336.60,而不是显示$336.6

(我知道这不是你的问题,但看看链接,我认为这可能对你有用。)

编辑-感谢Andy的建议。

money\u format()
是一个返回格式化数字字符串值的函数。你可以控制格式,当然还有你的号码。举个简单的例子,如果变量
$myNumber
中有您的值,您可以像这样将结果合并到给定表的数据单元中

<?php echo ("<td>".money_format('%n',$myNumber)."</td>"); ?>

您需要对每个值执行此操作,例如,如果您的所有值都在一个数组中,则通过
for
循环执行此操作。
n
这里是一个格式化选项-有几个。一个很好的地方是在
希望这能有所帮助。

我似乎无法正确使用。我使用echo的方式是

echo '<tr >

  <td ><a href="'.$offerlink.'" target="blank"><img src="http://www.nextadvisor.com'.$offerlogo.'" alt="'.$offername.'" /></a></td>

 <td ><span class="rating_text">Rating:</span><span class="star_rating1"><img src="http://www.nextadvisor.com'.$offerstar.'" alt="" /></span><br />

  <div style="margin-top:5px; color:#0000FF;"><a href="'.$offerlink.'" target="blank">Go to Site</a><span style="margin:0px 7px 0px 7px;">|</span><a href="'.$offeranchor.'">Review</a></div>   </td>

  <td >$'.$offerprice.'</td>

<td >$'.$offercalcsavingsann.'</td>


   </tr>';
echo'
评级:
| 美元。$offerprice。” 美元。$OFFERCALCAVINGSANN' ';
我把“设置区域设置”放在

 "<?php" 

“money\u格式更适合于货币格式。是的,但是我应该把“number\u格式”放在哪里?我不确定它的用法。我应该把它放在第一个“echo”之后还是放在单个值之前?