有人能告诉我如何比较字段表达式(textFieldExpression)中的两个大小数值吗?我正在使用iReport 3.0.0。
大于的语法是什么
这是我的表达式,它有效,但只显示两个值不相等的情况,我需要检查哪个值更大(amount > paid_amount
)。
我使用这个表达式:
($F{paid_date}!=null & ($F{amount}.equals($F{paid_amount}))) ? new String ("PAID") :(
($F{paid_date}==null) ? new String ("NOT PAID"): (
($F{paid_date}!=null & (!$F{amount}.equals($F{paid_amount}))) ? new String ("PARTIALLY PAID"):(new String ("INVOICE MISSING "))))
对于这样的字段:
<field name="amount" class="java.math.BigDecimal"/>
<field name="paid_amount" class="java.math.BigDecimal"/>
您应该使用以下表达式:
<textFieldExpression class="java.lang.String"><![CDATA[$F{amount}.compareTo($F{paid_amount}) == 1
? "The amount value is greater than the paid_amount value"
: $F{amount}.compareTo($F{paid_amount}) == 0 ?
"The amount value is equal to the paid_amount value" :
"The amount value is less than the paid_amount value"]]></textFieldExpression>
此表达式基于int BigDecimal.compareTo(java.math.BigDecimal val)方法。