I am designing my reports using Jasper reports, I have an income expense report where I am getting total Income using a variable TOT_INCOME
and total Expenses using a second variable, TOT_EXPENSES
. I need to Subtract the two variable to get the Net Profit.
So I have Created a third Variable TOT_PROFIT
. I am trying to get the Difference this way. On the third Variable Variable Expresion, I have:
$V{TOT_INCOME}-$V{TOT_EXPENSE}
as My expression. I am getting a wrong output. For example I have this Output:
TOTAL_INCOME TOTAL_EXPENSES PROFIT
215,762.00 16,012.00 1,587,228.00
Which is clearly Wrong as 215,762.00-16,012 = 199,750.00
. All my values are doubles. On the Third Variable, my calculation is sum
. Please Help where I might be doing a Mistake.
Because I want others who might have the same problem to find a solution, I will post what finally worked after tirelessly looking for a solution:
new Double($V{TOT_EXPENSE}.doubleValue() == 0 ? 0 : ($V{TOT_INCOME}.doubleValue()-$V{TOT_EXPENSE}.doubleValue()))
Done!! This Worked for me.