2013-12-10 35 views
0
$invoiceTotal = $settings['Setting']['currency'] . $thisInvoice['Invoice']['invoice_total']; 

$bedrag = $settings['Setting']['currency'] . number_format($thisInvoice['Payment']['0']['amount'], 2, '.', ','); 

$openbedrag = $invoiceTotal - $bedrag; 

//$invoiceTotal = 2 
//$bedrag = 1 

为什么$openbedrag = $invoiceTotal - $bedrag;无法正常工作?无法计算值

这是一个简单的计算,为什么它不计算这个变量?

它输出0 -_-”

UPDATE问题修正

$invoiceTotal = $settings['Setting']['currency'].$thisInvoice['Invoice']['invoice_total']; 
$bedrag = $settings['Setting']['currency'].number_format($thisInvoice['Payment']['0']['amount'], 2, '.', ','); 
$openbedrag2 = $thisInvoice['Invoice']['invoice_total'] - $thisInvoice['Payment']['0']['amount']; 
$openbedrag = $settings['Setting']['currency'].$openbedrag2; 

货币设置€

+4

当数字以货币符号开头时,您无法进行算术运算。 – Barmar

+0

什么$设置['设置'] ['货币']这部分包含?价值或符号? – ripa

+0

@ripa它大概包含一个货币符号,例如美元为'$'或英镑为''''。 – Barmar

回答

1

你需要做的算术与原始数字,而不是格式化 那些。

$openbedrag = $thisInvoice['Invoice']['invoice_total'] - $thisInvoice['Payment']['0']['amount']; 
+0

感谢,愚蠢的我。在数字之前忘了'$ settings ['Setting'] ['currency']' - ' - ' – user3078542

0

转换成整数: -

$openbedrag = ($invoiceTotal * 1.0) - ($bedrag * 1.0); 
+0

相同的输出显示为0 – user3078542

+0

当您使用算术运算符时,PHP会自动将字符串转换为整数。 – Barmar

+0

@ user3078542:请确保您的货币值没有货币符号 – Suleman

0

如果$设置[ '环境'] [ '货币']这种含符号,尽量避免使用$设置[ '环境'] [ '货币']在你的计算时间。所以你的计算会像下面: -

$invoiceTotal = $thisInvoice['Invoice']['invoice_total']; 

$bedrag = $thisInvoice['Payment']['0']['amount']; 

$openbedrag = $invoiceTotal - $bedrag; 

$openbedrag = $settings['Setting']['currency'].number_format($openbedrag, 2, '.', ','); 

注意: - 也不要在你的计算时间使用number_format。使用它在最终输出中计算后显示时间。