ttmt Posted December 8, 2012 Share Posted December 8, 2012 Hi all I have simple page here to illustrate my question. http://www.ttmt.org.uk/forum/discount/ It's a function that calculates a percentage of a given number. My problem is if the percentage calculated ends with a zero it isn't displayed as in the second number on the example page. I would like the second example to display £5.50 <!DOCTYPE html> <html> <meta charset="UTF-8"> <title>Title of the document</title> <style type="text/css"> *{margin:0;padding:0;} #wrap{margin:50px;} h3{display:block;font:1.2em Helvetica, sans-serif;color:#555;margin:0 0 15px 0;} .deletePrice{margin:0 20px 0 0;text-decoration:line-through} .discountRed{color:red;} </style> </head> <body> <div id="wrap"> <?php function item($price, $discount){ if($discount > 0){ $normPrice = $price; $normPriceDelete = "<span class='deletePrice discountRed'>£$normPrice</span>"; $price = ($discount/100)*$normPrice; $discountPrice = "<span class='price'>£$price</span>"; global $priceBlock; $priceBlock = "<span class='price deletePrice'>£$normPrice</span><span class='price discountRed'>£$price</span>"; echo "<h3>".$priceBlock."</h3>"; }else{ global $priceBlock; $priceBlock = "<span class='price'>£$price</span>"; echo "<h3>".$priceBlock."</h3>"; } } item(22,26); item(22,25); ?> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/271749-missing-zero-on-discount-calculation/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 8, 2012 Share Posted December 8, 2012 number_format Quote Link to comment https://forums.phpfreaks.com/topic/271749-missing-zero-on-discount-calculation/#findComment-1398230 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.