2016-11-23 73 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

好的,你介意分享你的問題的完整描述嗎? –