Post by dazoosh » Thu Mar 10, 2016 12:14 am

I am wanting to show the discount percentage amount between price and special price so added:

Code: Select all

<?php
preg_match('/\d+\.?\d*/', $price, $priceInt);
preg_match('/\d+\.?\d*/', $special, $specialInt);
?>

<h3><?php echo (($priceInt[0]-$specialInt[0])/$priceInt[0])*100 ?>% Discount</h3>
to /catalog/view/theme/default/template/product/product.tpl

My question is: How do I show the percentage as a whole number only?
eg. 12.34567890% = 12%

Thank you.

New member

Posts

Joined
Mon Dec 10, 2012 6:10 pm

Post by opencartboost » Thu Mar 10, 2016 7:06 am

Try use round

Code: Select all

<h3><?php echo round((($priceInt[0]-$specialInt[0])/$priceInt[0])*100, 0);  ?>% Discount</h3>
Ref :
http://php.net/manual/en/function.round.php

Active Member

Posts

Joined
Thu Jul 09, 2015 5:59 am

Post by dazoosh » Thu Mar 10, 2016 3:28 pm

opencartboost wrote:Try use round

Code: Select all

<h3><?php echo round((($priceInt[0]-$specialInt[0])/$priceInt[0])*100, 0);  ?>% Discount</h3>
Ref :
http://php.net/manual/en/function.round.php
That did it! Thank you very much. ;D

New member

Posts

Joined
Mon Dec 10, 2012 6:10 pm
Who is online

Users browsing this forum: No registered users and 11 guests