Home General

DisplayFormat and rounding

edited August 2015 in General
Hello,

we recently had some problems with wrong rounded values that were
displayed using a specific DisplayFormat.

To avoid any influence that may come from the database i have created a
very simple report that only contains one variable and assigned the
value "0.735" to that variable. The used DiaplayFormat is "#.00"

When the report is generated on Windows 7 or Windows 2008 Server the
variable shows a value of "0.74" which was correct.

On another test machine that has Windows 2003 Server installed the
displayed value was "0.73" which was wrong.

What may cause the values to be wrong on a machine with a different
operating system? Is there any locale setting that may cause this
difference?

Thanks in advance,
Ralf

Comments

  • edited August 2015
    Hi Ralf,

    Which version of ReportBuilder and Delphi are you using?

    ReportBuilder uses the Delphi routine FormatFloat to format numeric
    values such as the ones in your report. If you call FormatFloat on the
    same values outside ReportBuilder (in a separate Delphi app) you will
    get the same results. The issue is that these numbers cannot be
    accurately represented as binary values in Delphi so when they are sent
    through its rounding logic, inconsistent values are given. You can work
    around the issue in a number of ways.

    1. Alter the rounding mode of the FPU using the Math.SetRoundMode
    routine before printing your report. Setting this to rmUp or rmDown
    gives consistent results.

    2. Use a different datatype such as Currency.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited August 2015
    Am 04.08.2015 um 17:27 schrieb Nico Cizik (Digital Metaphors):

    Hello Nico,


    It is Version 15.


    That is what i tried after i wrote the message. For that report i get the
    results i wanted when i set the rounding mode. But we have lots of diffeent
    reports and i first have to check how such a setting would affect other results.

    The most interesting question at the moment for me is why i get different
    results on different operating systems. I have checked the locale settings on
    both systems and they seem to be the same (we are logging the current locale
    settings before generating the report to a logfile)

    I think i have missed one of the locale settings while logging but i have totaly
    no idea which setting it could be. (any idea??)

    Ciao,
    Ralf

    ---
    Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
    https://www.avast.com/antivirus
  • edited August 2015
    Hi Ralf,

    Floating point rounding discrepancies are not uncommon between operating
    systems and chip architectures. A quick search on Google will reveal
    countless articles and questions about this topic.

    The main issue (as I briefly explained in my previous post) is that all
    numerical values need to represented as a binary value as far as a the
    machine is concerned. Unfortunately, not all numbers can (for instance,
    the number 0.1 cannot be exactly represented as a finite binary value)
    and different OS's, chip architectures, and programming languages
    frequently handle these floating point numbers in different ways.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.