Jump to content

Missing Zero On Discount Calculation.


ttmt

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/271749-missing-zero-on-discount-calculation/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.