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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.