2013-07-25 97 views
0

计算从旧价格到新价格的折扣百分比时出现问题。当旧价格超过100美元时,折扣价值的百分比是错误的,但当低于100美元时,折扣的百分比是正确的。这个脚本有什么问题?真的需要你的帮助家伙.. 我使用Magento的1.4,折扣产品的错误计算

$_oldprice= substr(Mage::helper('core')->currency($_regularPrice,true,false),2); 
$_newprice= substr(Mage::helper('core')->currency($_finalPrice,true,false),2); 
$_discountprice= $_oldprice- $_newprice; 
$count1 = $_discountprice/$_oldprice; 
$count2 = $count1 * 100; 
$count = number_format($count2, 0); 

printscreen of the error discount

+0

有人帮我请.. –

+0

再次有人帮我请.. –

回答

0

$ discountPercentage =(($ _oldprice- $ _newprice)/ $ _ oldprice)* 100;

这是应该使用的公式。

+0

仍然一样,没有变化.. –

+0

((120-110)/ 120)* 100将是8.33%这是正确的。请确保你的根据数学优先级放置括号。这里120是旧价格,110是新价格。 – oscprofessionals

+0

如果仍然KO给我们一个例子请 – dagfr