减去两个变量 [英] Subtract two variable

查看:108
本文介绍了减去两个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jasper报告设计我的报告,我有一份收入费用报告,我使用变量 TOT_INCOME 获得总收入,并使用第二个变量获得总费用 TOT_EXPENSES 。我需要减去这两个变量来获得净利润。
所以我创建了第三个变量 TOT_PROFIT 。我试图通过这种方式获得差异。在第三个变量变量表达式中,我有:

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

这显然是错误的 215,762.00-16,012 = 199,750.00 。我所有的价值观都是双打的。在第三个变量上,我的计算是 sum 。请帮助我可能会犯错误。

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:


  1. 创建一个类型为Double的新文本字段,然后在您的内容中添加以下内容texfield表达式:

new Double($ V {TOT_EXPENSE} .doubleValue()== 0?0:
($ V {TOT_INCOME} .doubleValue() - $ V {TOT_EXPENSE} .doubleValue()))

new Double($V{TOT_EXPENSE}.doubleValue() == 0 ? 0 : ($V{TOT_INCOME}.doubleValue()-$V{TOT_EXPENSE}.doubleValue()))

完成!!这对我有用。

这篇关于减去两个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆