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.Stringtojava.lang.Double.You should also check that the field classes of
qpaandpriceare string, as that is whatparseDouble()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
javatogroovy, these casts will be performed automatically. I don’t recommend this though.)