Icon View Thread

The following is the text of the current message along with any replies.
Messages 11 to 15 of 15 total
Thread Rounding
Mon, Apr 11 2011 12:47 PMPermanent Link

Rita Tipton

Thanks Chris longtime no see or am I visually impaired that much ?
Rita


Mon, Apr 11 2011 1:22 PMPermanent Link

Rita Tipton

So what did Rita do she wrote her own rounding function.

function TfrmMain.RoundRita(x: Extended; d: Integer): Extended;
var n: Extended;
begin
n := IntPower(10, d);
x := x * n;
Result := (Int(x) + Int(Frac(x) * 2)) / n;
end;
Mon, Apr 11 2011 2:19 PMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Rita,

Ah I see, you were talking about Delphi rounding, and I was answering thinking of DBISAM rounding.
Delphi does 'Banker's rounding', and DBISAM does 'normal' rounding.
So yeah, if you want to round using the Delphi RoundTo() and get the same results as you do with DBISAM Round() you have to provide your own rounding function.

From DBISAM manual:
"The ROUND function performs "normal" rounding where the number is rounded up if the fractional portion beyond the number of decimal places being rounded to is greater than or equal to 5 and down if the fractional portion is less than 5"

However Delphi rounding uses "bankers rounding":
"RoundTo uses "Banker's Rounding" to determine how to round values that are exactly midway between the two values that have the desired number of significant digits. This method rounds to an even number in the case that AValue is not nearer to either value."

Anyway, no matter what method you use, the sum of rounded parcels is only by accident the same as rounding the sum of the same parcels.

--
Fernando Dias
[Team Elevate]
Mon, Apr 11 2011 3:47 PMPermanent Link

Aage J.


For "rounding", you might be interested in some work from John Herbster
- he posts often on embarcadero.public.delphi.non-technical.  You can
find his decimal rounding routines on CodeCentral:
  http://cc.embarcadero.com/Item/19421


--
Aage J.

Tue, Apr 12 2011 3:03 AMPermanent Link

Chris Holland

SEC Solutions Ltd.

Avatar

Team Elevate Team Elevate

Hi Rita,

I am hiding in the ODBC newsgroups mostly these days, being a .NET boy
now Smiley

Chris

On 11/04/2011 17:47, Rita wrote:
> Thanks Chris longtime no see or am I visually impaired that much ?
> Rita
>
>
>

--
Chris Holland
[Team Elevate]
« Previous PagePage 2 of 2
Jump to Page:  1 2
Image