GroupFooter Sum Precision Problem

PolomintPolomint Australia
edited May 2017 in FastReport VCL 5
In a Share Portfolio Report for a client, we have encountered a strange problem which we solved by doing calculations in Delphi "GroupFooterBeforePrint" code**.

But I would like to know why this happens, and how we can avoid it in future [img]style_emoticons/<#EMO_DIR#>/cool.gif" style="vertical-align:middle" emoid="B)" border="0" alt="cool.gif" /> In the attached cut-down report we have: - a[/img]DetailBand which is a TfrxMasterData containing ShareValuePrice, ShareValuesGrossAmount and ShareValuesSumOfCount
- a GroupFooter which is a TfrxGroupFooter containing GroupSumPrice

The fields below are all TfrxMemoView:
- ShareValuePrice gets its data from [ShareValues."Price"]
- ShareValuesGrossAmount gets its data from [ShareValues."Gross Amount"]
- ShareValuesSumOfCount gets its data from [ShareValues."SumOfCount"]
- GroupSumPrice gets its data from [Sum(<ShareValues."Gross Amount">)/Sum(<ShareValues."SumOfCount">)]

The DataSet "ShareValues" is a Query which rolls up trades over a period and groups data into Company and Class of Share values. The GroupFooter should present a summing by Company of all the Class of Share amounts. The prices are "notional" since the "absolute" values are the Gross Amount spent to acquire the Shares, and the Number of Shares held, and therefore not required to be rounded to currency precision.

Regardless of what we do (currently setting DisplayFormat.FormatStr="%6.6n" DisplayFormat.Kind="fkNumeric" for example), the result for the Calculated Price is always rounded to four decimal places, as if it had been processed by FormatCurr. Note that the source data (from the summing in the Query) in the test example is shown at the expected precision (being the result of dividing $54,541.15 by 2,628). It is the Sum in FastReports that seems to cause the issue. I've zeroed the other data items to simplify the data.

I have only recently upgraded our licence from Standard to Professional, so have not had the Source Code long enough to be completely au fait with it. A cursory examination of frxClass.pas showed me nothing that indicated why this was happening, but perhaps I am looking in the wrong place.

Any suggestions?

Comments

  • gpigpi
    edited 8:20PM
    Try to set TfrxDBDataset.BCDToCurrency to True
  • PolomintPolomint Australia
    edited May 2017
    OK I set TfrxDBDataset.BCDToCurrency to True and reversed out the changes that moved the code to Delphi.

    Sadly, the result is the same, i.e. the value calculated within FastReport is still being rounded to four decimal places.

  • gpigpi
    edited 8:20PM
    Create small demo project with problem based on standart Delphi's components and local database like MS Access mdb and send it to support@fast-report.com
  • PolomintPolomint Australia
    edited 8:20PM
    Thanks GPI,

    Done. Results of original report reproduced:
    - With BCDtoCurrency = FALSE and also = TRUE
    - Within the IDE (i.e. before compilation) and also the executable file


    >
  • gpigpi
    edited 8:20PM
    wrote:
    Test materials coming to you shortly via email.
    Sorry, but I don't see new tickets. Tell me your ticket number
  • PolomintPolomint Australia
    edited 8:20PM
    gpi wrote: »
    Sorry, but I don't see new tickets. Tell me your ticket number
    My misunderstanding, I thought you were expecting an email [img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> Ticket #438673 (GroupFooter Sum Precision Problem, Why are calculated values rounded to four places?) Cheers, Paul[/img]
  • PolomintPolomint Australia
    edited 8:20PM
    Polomint wrote: »
    Ticket #438673 (GroupFooter Sum Precision Problem, Why are calculated values rounded to four places?)
    Solution offered to problem is to modify the SQL Select statement, replacing
    Sum([Amount]+[Brokerage]) AS [Gross Amount]
    with
    Sum([Amount]+[Brokerage])/1 AS [Gross Amount]

    This worked in the test program. All calculated "Prices" are to the expected level of precision. >

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.