你们昨天是非常有益的。我还是有点虽然这里混淆。

我希望让这个最右栏的数字四舍五入为最接近的美元:

http://www.nextadvisor.com/voip_services/voip_calculator .PHP?monthlybill = 50&提交=提交

表的代码看起来是这样的:

我想$报价[1,2,3,4,5,6,7] calcsavingsann要舍,如何才能做到这一点?

 <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>
有帮助吗?

解决方案

你想四舍五入/下/截断到最近的美元?

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

<强>舍入

地板

小区

<强>格式化/截断情形

的sprintf

其他提示

Grepsedawk的回答是好;我想补充的唯一事情是不是显示$ 336.6,例如,你可以可以使用 number_format 输出$ 336.60 。

(我知道这不是你的问题,但看的联系,我想这可能是对你有用。)

编辑 - 。由于安迪用于建议 money_format 代替

money_format()是一个返回格式的数字的字符串值的函数。您可以通过格式化控制,很明显,你的电话号码。一个简单的例子,如果在可变$myNumber有你的值,可以合并的结果到一个给定表的数据单元像这样;

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

和你需要为每一个值,例如做通过for循环,如果你有数组中的所有你的价值观。这里的n是格式化选项之一 - 有几个。一个很好的地方去寻找会在 HTTP的PHP网页上:/ /au2.php.net/manual/en/function.money-format.php 希望这有助于。

我似乎无法得到使用权。我使用回声的方法是

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>';

我把“设置区域”向上其中

 "<?php" 

是。我不知道怎么写,每一个方式,我做只是返回一个错误。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top