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())
精彩评论