开发者

How to multiply two string fields in JasperReports?

开发者 https://www.devze.com 2023-04-04 09:16 出处:网络
How do I multiply two fields of type string (say, price and quantity) to obtain a result of type double? How to write this in an XML file?

How do I multiply two fields of type string (say, price and quantity) to obtain a result of type double? How to write this in an XML file?

I tried this in a variable expression, but it is not working:

开发者_开发知识库
new Double(Double.parseDouble($F{qpa}) * Double.parseDouble($F{price}))]]


JasperReports will not automatically cast the variable expression to the variable class. @Vicky, your variable expression works for me once I changed the variable class from the default java.lang.String to java.lang.Double.

You should also check that the field classes of qpa and price are string, as that is what parseDouble() is expecting.

Also, if you are going to print the value of the variable in a textField, the expression class must also be changed to java.lang.Double.

(This only applies if you are writing your expressions in Java. If you change your report language from java to groovy, these casts will be performed automatically. I don't recommend this though.)


Try to use this expression:

Double.valueOf(Double.valueOf($F{qpa}).doubleValue()*Double.valueOf($F{price}).doubleValue())
0

精彩评论

暂无评论...
验证码 换一张
取 消