Re: Bug in Delphi SimpleRoundTo function?



"James Miller" wrote
I am pretty sure that Delphi's Currency type
calculations also use bankers rounding. Is there
a compiler switch or something to make it use
simple rounding?

A good programmer should know that there is no such
thing as "simple rounding" -- by that, I mean a
rounding rule that most programmers can agree on.
At least "bankers rounding" is a rule that most
programmers can agree on.

That aside, when ordinary programmers get caught in
the trap of using floating *binary* point numbers,
to represent (fixed or floating) decimal fraction
numbers and have to do any kind of rounding, then
they stumble all over themselves.

The problem, of course, is that general decimal
fractions cannot be exactly represented as
floating binary point numbers. This leads to
problems deciding what the floating binary point
number is really supposed to represent in decimal
fraction terms. My DecimalRounding package that
Willem mentioned solves this problem.

However, as someone ready to step into retirement
who has for many years tried both to educate the
ignorant and to push for incorporating actual
fixed and floating decimal fraction into Delphi,
I am really disappointed that I am still reading
such ill informed discussion of this problem.

Rgds, JohnH

--
Support the movement to add floating and fixed
decimal fraction numbers to Delphi.
http://qc.borland.com/wc/qcmain.aspx?d=28022

DecimalRounding (JH1) -- allows you to do about
nine kinds of decimal rounding with floating
binary point numbers.
http://cc.codegear.com/Item.aspx?id=21909

IEEE Number Analyzer (project source code) -- a
program that will convert a decimal fraction
number into the nearest possible floating binary
point number (i.e. single, double, or extended)
http://cc.codegear.com/item.aspx?id=23631

ExactFloatToStr -- a function for converting a
floating binary point number to its exact
decimal fraction values in a ASCII string.
http://cc.codegear.com/Item.aspx?id=19421
.



Relevant Pages

  • Re: Why not FP for Money?
    ... I had started with the assumption that the IEEE 754 rounding methods ... accounting has rules about rounding, ... Floating point arithmetic is useful for continuous quantities, ... applies here if you are dealing with actual pennies. ...
    (comp.lang.python)
  • Re: converting float to double
    ... Although I can not see a guarantee from your floating ... rounding, it does not generalise to, e.g., ...
    (comp.lang.c)
  • Cfv: Floating point truncation
    ... RfD: Floating point truncation ... which, respectively, provide rounding to the nearest integer, and rounding to the nearest integer on the side of the number line towards negative infinity. ... ANS Forth does not provide a word for rounding towards zero, and returning a floating point representation of the resulting integer. ... Include a standard word, named "FTRUNC", to perform "truncation", i.e. rounding of a floating point number towards zero, returning a floating point representation of the resulting integer. ...
    (comp.lang.forth)
  • Re: converting float to double
    ... > the floating point value. ... The "rounding" required to ... What algorithm should be implemented? ... If accounting rules so specifiy, ...
    (comp.lang.c)
  • Re: Wierd Floainting-Point behaviour... HELP PLEASE.
    ... you still find that the control word ... when trying to do decimal fraction rounding on a floating ...
    (borland.public.delphi.language.basm)