英文:
rounding issue - VFP
问题
从本地VFP9命令窗口:
lyTotal_Revenue=16571.39
lyExcludeFromRent=1673.88
lnRentPercent=30
lnanswer=((lyTotal_Revenue - lyExcludeFromRent) * (lnRentPercent / 100))
?lnanswer 显示 4469.253
这是正确的答案。
我有一个报表,其中有一个字段。该字段的格式表达式是9,999,999.99
字段的格式选项为Currency
字段上的表达式是round(((lyTotal_Revenue-lyExcludeFromRent) * (lnRentPercent/100)),2)
为什么报表显示$4,969.26
英文:
From Native VFP9 command window:
lyTotal_Revenue=16571.39
lyExcludeFromRent=1673.88
lnRentPercent=30
lnanswer=((lyTotal_Revenue - lyExcludeFromRent) * (lnRentPercent / 100))
?lnanswer shows 4469.253
That is the correct answer.
I have a report that has a field. The field's format expression is 9,999,999.99
The field's format options is Currency
The expression on the field is round(((lyTotal_Revenue-lyExcludeFromRent) * (lnRentPercent/100)),2)
Why does the report show $4,969.26
答案1
得分: 2
我终于意识到问题出在哪里。我的报告包括常规内容,即详细行和总计行。列包括收入和ExcludeFromRent。总计行只是详细行的总和。因此,总计行上有相同的字段,但它们的计算选项标签上有"Sum on Report"。我还有一个摘要页面。该摘要页面对总计行的值进行一些数学运算。伪代码中的数学运算是租金收入 = (总收入减去总ExcludeFromRent)。然后AmountToPay = Rent Revenue * (lnRentPercent / 100)。因此,摘要部分的字段表达式为round(((Revenue-ExcludeFromRent) * (lnRentPercent/100)),2),计算选项标签上为"Sum on Report"。这有什么问题吗?每当处理详细行时,摘要字段上的表达式都会执行。这意味着我会对每个详细行进行四舍五入,并将该值添加到摘要字段中。我改为在调用报告之前计算Revenue和ExcludeFromRent的总和,然后执行表达式round(((Revenue-ExcludeFromRent) * (lnRentPercent/100)),2)一次,并将值放入一个私有变量中。摘要字段的表达式是私有变量,计算选项标签上说"None"。
John
编辑:任何变量、数组、属性等都可以从报告内部访问(因为报告在技术上是在同一例程内运行的命令)。即:(忽略我正在进行的计算的正确性,我知道它不正确)
local lnTotalRevenue, lnExcludeFromRent, lnPercent
local array laRevenue[1]
select sum(Revenue) from myTable into array laRevenue
lnPercent = 30
lnTotalRevenue = round(laRevenue[1] - m.lnExcludeFromRent,2)
thisform.Tag = 'Rent Information'
report form MyReport ...
在报告内部,您可以访问所有这些lnTotalRevenue、lnExcludeFromRent、lnPercent、laRevenue、thisform.Tag。这有时可能非常有价值。
英文:
I finally realized what the issue is. My report has the normal stuff meaning detail lines and a total line. Columns are Revenue and ExcludeFromRent. The total line is simply the sum of the detail lines. So I have the same fields on the total line but their Calculation tab has Sum on Report. I also have a summary page. That summary page does some math on the values from the total line. The math in pseudocode is Rent Revenue = (Total Revenue minus Total ExcludeFromRent). Then AmountToPay = Rent Revenue * (lnRentPercent / 100). So, the field in the summary section has an expression of round(((Revenue-ExcludeFromRent) * (lnrentpct/100)),2) and the Calculation tab has Sum on Report. What is wrong with this? Everytime a detail line gets processed the expression on the summary field is executed. That means I am rounding each detail row and adding that value to the summary field. What I did instead: I calculate the sum of the Revenue and ExcludeFromRent before calling the report and then execute the expression round(((Revenue-ExcludeFromRent) * (lnrentpct/100)),2) ONCE and place the value in a private variable. The expression for the summary field is the private variable and the Calculation tab says None.
John
EDIT: Any variable, array, for property etc are visible from within the report (because report is a command running technically within the same routine). ie: (discard the correctness of calculation I am doing, it is not, I know)
local lnTotalRevenue, lnExcludeFromRent, lnPercent
local array laRevenue[1]
select sum(Revenue) from myTable into array laRevenue
lnPercent = 30
lnTotalRevenue = round(laRevenue[1] - m.lnExcludeFromRent,2)
thisform.Tag = 'Rent Information'
report form MyReport ...
Within the report you have access to all those lnTotalRevenue, lnExcludeFromRent, lnPercent, laRevenue, thisform.Tag. This may be of great value sometimes.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论