簡體   English   中英

基本的PHP表單幫助(貨幣顯示)

[英]basic php form help (currency display)

昨天你們非常有幫助。 我仍然有點困惑。

我想這樣做,以便最右邊一列的數字四舍五入為最接近的美元:

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

該表的代碼如下所示:

我想將$ offer [1,2,3,4,5,6,7] calc Savingsann進行四舍五入,該怎么辦?

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

您要四舍五入到最接近的美元嗎?

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

四舍五入

回合

地板

細胞

格式化/截斷

沖刺

Grepsedawk的回答很好。 我唯一要添加的是,例如,您可以使用number_format輸出$ 336.60,而不是顯示$ 336.6。

(我知道這不是您的問題,但是查看鏈接,我認為這可能對您有用。)

編輯-感謝Andy提出了money_format的建議。

money_format()是一個返回格式化數字的字符串值的函數。 您可以控制格式,當然也可以控制您的號碼。 一個簡單的例子,如果您的值位於變量$myNumber ,則可以將結果合並到給定表的數據單元中,如下所示:

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

而且,您需要對每個值執行此操作,例如for如果將所有值都放在數組中,則需要通過for循環。 這里的n是格式設置選項之一-有多個。 可以在PHP網頁http://au2.php.net/manual/en/function.money-format.php上找到一個不錯的地方,希望這會有所幫助。

我似乎無法正確使用。 我使用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>';

我將“設置區域設置”放在

 "<?php" 

是。 我不明白該怎么寫,而我做的每一種方式都只會返回一個錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM