I am currently building a XML based Jasper Report in which I am trying to add a tax percent onto the cost.
A problem occurs when I use sum(//net-total) to value calculate the total cost. When the summed total has no decimal places it returns and Integer and I need a double.
I have tried sum(//net-total) * 1.0 but it doesn’t seem to work.
Does anyone have any ideas?
Please feel free to correct me if I am taking the wrong approach.
The problem is that by definition (of XML) a double must have a decimal point (.)
[ http://www.w3.org/TR/xmlschema-2/#double ]
You should take a look at the XSLT format-number() Function ..
for example
format-number(sum(//net-total), "#.00")would enforce a two decimal digits representation ..[EDIT]
Since you want it for XPATH 1, which unfortunately does not support conditional expressions nor string formatting , it is not possible to do it in a signle xpath expression …
if however you can create a node (sum-total) with the sum of the //net-total then you could use a little workaround
which will add .00 if there is no . in the node value ..