2016-11-23 78 views
0

结合如何有一定的PHP作为加法对PHP计算如何两个PHP计算

这是基本代码

<?php echo (str_replace('.',',',round((str_replace(',','.',(str_replace('€','',$discount['discountedPrice'])))*1.2),2)))." Eur"; ?> 

,并想添加以下内容:

(str_replace('.',',',round((str_replace(',','.',(str_replace('€','',$discount['discountAmount'])))*0.2),2))) 

所以我想补充(+),看起来像这样,但不知道如何把它:

(str_replace('.',',',round((str_replace(',','.',(str_replace('€','',$discount['discountedPrice'])))*1.2),2))) + (str_replace('.',',',round((str_replace(',','.',(str_replace('€','',$discount['discountAmount'])))*0.2),2))) 
+0

您可以使用PHP构建功能money_format。看看文档 - > http://php.net/manual/en/function.money-format.php –

+1

一会儿我以为这是一个lisp问题 – Federkun

+0

我只是想将以下内容加在一起,然后它会工作...像第一代码+第二代码 –

回答

0

你去那里:

<?php 

$value120Percent = round(removeEuroChangeDecimal($discount['discountedPrice']) * 1.2, 2); 
# or if you really don't need rounding 
# $value120Percent = removeEuroChangeDecimal($discount['discountedPrice']) * 1.2; 
$value20Percent = round(removeEuroChangeDecimal($discount['discountAmount']) * 0.2, 2); 
# or if you really don't need rounding 
# value20Percent = removeEuroChangeDecimal($discount['discountAmount']); 

# change the fourth parameter to set thousands separator (to e.g. a space) 
echo number_format($value120Percent + $value20Percent, 2, ',', ''); 

function removeEuroChangeDecimal($value) { 
    return str_replace(',', '.', str_replace('€','', $value)); 
} 
+0

感谢您的建议 。替代欧元符号和点的代码应该被替换,因为货币有时不是欧元。 –

+0

也有其他的代码,有些价格是欧元,不需要改变....上面的代码会影响他们吗? –

+0

好的,你介意分享你的问题的完整描述吗? –