Question

Vous avez été très utiles hier. Je suis toujours un peu confus ici cependant.

Je souhaite que les chiffres de la colonne de droite soient arrondis au dollar près:

http://www.nextadvisor.com/voip_services/voip_calculator .php? MonthlyBill = 50 & Submit; Submit = Submit

le code de la table ressemble à ceci:

Je veux que $ offer [1,2,3,4,5,6,7] calcsavingsann soit arrondi, comment peut-on y arriver?

 <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>
Était-ce utile?

La solution

Voulez-vous arrondir au dollar supérieur le plus proche, haut / bas /

?

Voici quelques fonctions suggérées que vous pouvez utiliser:

Arrondissement

rond

étage

ceil

Formatage / Troncature

sprintf

Autres conseils

La réponse de Grepsedawk est bonne; La seule chose que je voudrais ajouter est qu'au lieu d'afficher 336,6 USD, par exemple, vous pourriez utiliser number_format pour générer 336,60 USD. .

(Je sais que ce n'était pas votre question, mais en regardant le lien, j'ai pensé que cela pourrait vous être utile.)

Modifier - Merci à Andy d’avoir proposé money_format à la place.

money_format () est une fonction qui renvoie la valeur sous forme de chaîne d'un nombre formaté. Vous avez le contrôle sur le formatage et, évidemment, sur votre nombre. Un exemple simple, si vous avez votre valeur dans la variable $ myNumber , vous pouvez incorporer le résultat dans la cellule de données d'une table donnée, comme suit:

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

Et vous devez le faire pour chaque valeur, par exemple. via une boucle pour si vous aviez toutes vos valeurs dans un tableau. Le n est l’une des options de formatage. Il y en a plusieurs. Vous trouverez un bon endroit sur la page Web PHP à l'adresse http: / /au2.php.net/manual/en/function.money-format.php J'espère que cela vous aidera.

Je n'arrive pas à obtenir un bon usage. La façon dont j'utilise echo est

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 >

J'ai mis les "paramètres régionaux définis" là où le

 "<?php" 

est. Je ne comprends pas comment l'écrire et chaque manière que je renvoie ne renvoie qu'une erreur.

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

J'ai mis les "paramètres régionaux définis" là où le

<*>

est. Je ne comprends pas comment l'écrire et chaque manière que je renvoie ne renvoie qu'une erreur.

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

J'ai mis les "paramètres régionaux définis" là où le

<*>

est. Je ne comprends pas comment l'écrire et chaque manière que je renvoie ne renvoie qu'une erreur.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top