2016-09-22 32 views
2

我知道如何爲某些簡單值創建空值0。例如,我爲自己的文本字段中輸入以下表達式:當使用Jasper Studio時爲0時,值爲0

($V{current_val_subtotal} != null) ? $V{current_val_subtotal} : "0.00" 

其中$V{current_val_subtotal}BigDecimal。但我想做到以下幾點:

(($F{CurrentValue}.doubleValue()/$V{current_val_subtotal}.doubleValue())*100 != null) ? ($F{CurrentValue}.doubleValue()/$V{current_val_subtotal}.doubleValue())*100 : 「0.00」 

其中$F{CurrentValue}BigDecimal

當預覽報告中,我得到了以下錯誤:

The operator != is undefined for the argument type(s) double, null 
Errors were encountered when compiling report expression class file: 
+0

@DmitrySmorzhok是正確的。如果有的話,你應該在開頭檢查'($ V {current_val_subtotal}!= null)'以避免被零除。 – tobi6

回答

1

什麼是你真正期待?表達式someDouble/someDouble != null的含義是什麼?

您有兩個基元的分割,它們永遠不會導致null:如果BigDecimal都是非null,您可以獲得一個double,否則可以獲得一個double。否則,返回NullPointerException。這就是爲什麼你會收到編譯錯誤。

你可能想是這樣的

($F{CurrentValue} != null && $V{current_val_subtotal} != null) ? 
($F{CurrentValue}.doubleValue()/$V{current_val_subtotal}.doubleValue() * 100) : 0 

($F{CurrentValue} != null && $V{current_val_subtotal} != null) ? 
($F{CurrentValue}.divide($V{current_val_subtotal}, 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)) : BigDecimal.ZERO 
相關問題