문제

너희들은 어제 매우 도움이되었다. 나는 여전히 여기서 약간 혼란스러워합니다.

가장 오른쪽 열의 숫자가 가장 가까운 달러로 반올림되도록 만들고 싶습니다.

http://www.nextadvisor.com/voip_services/voip_calculator.php?monthlybill=50&submit=submit

테이블 코드는 다음과 같습니다.

나는 $ 제안 [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을 표시하는 대신 사용할 수 있다는 것입니다. 숫자 _format $ 336.60을 출력합니다.

(나는 이것이 당신의 질문이 아니라는 것을 알고 있지만, 링크를 보면, 그것이 당신에게 유용 할 것이라고 생각했습니다.)

편집 - 제안해 주신 Andy에게 감사합니다 Money_format 대신에.

money_format() 형식 숫자의 문자열 값을 반환하는 함수입니다. 당신은 서식 및 분명히 번호를 제어 할 수 있습니다. 간단한 예, 변수에 값이있는 경우 $myNumber, 결과를 주어진 테이블의 데이터 셀에 포함시킬 수 있습니다.

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

그리고 당신은 모든 가치에 대해이 작업을 수행해야합니다. 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 ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top