Icon View Thread

The following is the text of the current message along with any replies.
Messages 11 to 20 of 30 total
Thread round
Tue, Feb 26 2008 6:29 PMPermanent Link

"Gregory Sebastian"
<<How do I make sure, both oundings are the same?!>>
Sorry Andrej, I'm not really sure. I'd might just use Delphi for both if I
were in your shoes.

Regards
Gregory Sebastian
Wed, Feb 27 2008 6:12 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Andrej,

<< Once I round "in Delphi" and once I round "in SQL". But I need the same
results. How do I make sure, both oundings are the same?! >>

If you want a different type of rounding function in DBISAM, you can
implement one using custom functions:

http://www.elevatesoft.com/scripts/manual.dll?action=mantopic&id=dbisam4&product=d&version=7&category=1&topic=8

(under "Custom SQL and Filter Functions")

--
Tim Young
Elevate Software
www.elevatesoft.com

Tue, Mar 4 2008 1:20 PMPermanent Link

Sanford Aranoff
"Tim Young [Elevate Software]" wrote:
>
> Andrej,
>
> << Once I round "in Delphi" and once I round "in SQL". But I need the same
> results. How do I make sure, both oundings are the same?! >>
>
> If you want a different type of rounding function in DBISAM, you can
> implement one using custom functions:
>
> http://www.elevatesoft.com/scripts/manual.dll?action=mantopic&id=dbisam4&product=d&version=7&category=1&topic=8
>
> (under "Custom SQL and Filter Functions")
>
> --
> Tim Young
> Elevate Software
> www.elevatesoft.com

Bankers rounding is the only one that makes sense. Now I am
confused. I understand that Delphi (including D5) does
bankers rounding. From Delphi Help:

X is a real-type expression. Round returns an Int64 value
that is the value of X rounded to the nearest whole number.
If X is exactly halfway between two whole numbers, the
result is always the even number.

How does sql do rounding?
Tue, Mar 4 2008 3:00 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Sanford,

<< How does sql do rounding? >>

SQL doesn't "do" rounding, period.  The rounding functions are all extended
functions that aren't described in the SQL spec.

DBISAM's implementation performs rounding according to what is described in
the 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. Also, if using the ROUND function with floating-point
values, it is possible to encounter rounding errors due to the nature of
floating-point values and their inability to accurately express certain
numbers. If you want to eliminate this possibility you should use the CAST
function to convert the floating-point column or constant to a BCD value
(DECIMAL or NUMERIC data type in SQL). This will allow for the rounding to
occur as desired since BCD values can accurately represent these numbers
without errors."

--
Tim Young
Elevate Software
www.elevatesoft.com

Tue, Mar 4 2008 8:12 PMPermanent Link

Sanford Aranoff
"Tim Young [Elevate Software]" wrote:
>
>>
> DBISAM's implementation performs rounding according to what is described in
> the 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. Also, if using the ROUND function with floating-point
> values, it is possible to encounter rounding errors due to the nature of
> floating-point values and their inability to accurately express certain
> numbers. If you want to eliminate this possibility you should use the CAST
> function to convert the floating-point column or constant to a BCD value
> (DECIMAL or NUMERIC data type in SQL). This will allow for the rounding to
> occur as desired since BCD values can accurately represent these numbers
> without errors."
>
> --
> Tim Young
> Elevate Software
> www.elevatesoft.com

This contradicts what I read in help:
From Delphi Help:

X is a real-type expression. Round returns an Int64 value
that is the value of X rounded to the nearest whole number.
If X is exactly halfway between two whole numbers, the
result is always the even number.

  x:= 2.5;
  i:= round(x); // 2
  x:= 3.5;
  i:= round(x); // 4
Tue, Mar 4 2008 9:22 PMPermanent Link

"Jeff Cook"
Sanford Aranoff wrote:

>
> X is a real-type expression. Round returns an Int64 value
> that is the value of X rounded to the nearest whole number.
> If X is exactly halfway between two whole numbers, the
> result is always the even number.
>
>    x:= 2.5;
>    i:= round(x); // 2
>    x:= 3.5;
>    i:= round(x); // 4

But when Tim says "normal" rounding, he probably referes to the common
method as in this http://en.wikipedia.org/wiki/Rounding - Googling for
rounding is a recipe for a waste of time as there is much written and
much argument e.g. http://thedailywtf.com/Comments/Round_and_Round.aspx


--
Jeff Cook
Aspect Systems Ltd
www.aspect.co.nz
+
Joan and Jeff Cook
The Cooks Oasis
www.cookislandsoasis.com
Tue, Mar 4 2008 10:05 PMPermanent Link

Sanford Aranoff
>
> But when Tim says "normal" rounding, he probably referes to the common
> method as in this http://en.wikipedia.org/wiki/Rounding - Googling for
> rounding is a recipe for a waste of time as there is much written and
> much argument e.g. http://thedailywtf.com/Comments/Round_and_Round.aspx
>
> --
> Jeff Cook
> Aspect Systems Ltd
> www.aspect.co.nz
> +
> Joan and Jeff Cook
> The Cooks Oasis
> www.cookislandsoasis.com

The common method is the standard.
The Round-to-even method has been the ASTM (E-29) standard
since 1940.
http://en.wikipedia.org/wiki/Rounding

The other idea is common sense. I do not understand the
justification for anything else, because of the errors it
introduces.
Tue, Mar 4 2008 10:10 PMPermanent Link

Sean McCall
Sanford,

I am guessing that Tim was talking about the ROUND function in DBISAM.
You are quoting the Delphi manual which talks about the Round function
in the system unit.

How you want to round depends on what your users expect. There is no
right or wrong way. Most people were taught and expect what Tim calls
"normal" rounding:

2.5 ==> 3
3.5 ==> 4

Start dealing with negative numbers and you could make a valid argument
for rounding either up or down.

Bankers rounding is an attempt to average out the up rounding with the
down rounding by going to the nearest even number. I believe that this
is the default rounding for the FPU and so it is what Delphi uses since
it is the fastest way to perform the calculation.

If rounding is important to your application, know what the functions do
and use the rounding that is most appropriate for your circumstances. I
would recommend that you write your own function for rounding so that
you can have complete control over how it is done.


Sean




Sanford Aranoff wrote:
> "Tim Young [Elevate Software]" wrote:
>> DBISAM's implementation performs rounding according to what is described in
>> the 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. Also, if using the ROUND function with floating-point
>> values, it is possible to encounter rounding errors due to the nature of
>> floating-point values and their inability to accurately express certain
>> numbers. If you want to eliminate this possibility you should use the CAST
>> function to convert the floating-point column or constant to a BCD value
>> (DECIMAL or NUMERIC data type in SQL). This will allow for the rounding to
>> occur as desired since BCD values can accurately represent these numbers
>> without errors."
>>
>> --
>> Tim Young
>> Elevate Software
>> www.elevatesoft.com
>
> This contradicts what I read in help:
> From Delphi Help:
>
> X is a real-type expression. Round returns an Int64 value
> that is the value of X rounded to the nearest whole number.
> If X is exactly halfway between two whole numbers, the
> result is always the even number.
>
>    x:= 2.5;
>    i:= round(x); // 2
>    x:= 3.5;
>    i:= round(x); // 4
Wed, Mar 5 2008 10:40 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Sanford,

<< This contradicts what I read in help: From Delphi Help: >>

That's because the SQL round function is not the same thing as the Delphi
round function.  They're two completely different languages/implementations.

--
Tim Young
Elevate Software
www.elevatesoft.com

Wed, Mar 5 2008 9:45 PMPermanent Link

Sanford Aranoff
Sean McCall wrote:
>
> Sanford,
>
> I am guessing that Tim was talking about the ROUND function in DBISAM.
> You are quoting the Delphi manual which talks about the Round function
> in the system unit.
>
> How you want to round depends on what your users expect. There is no
> right or wrong way. Most people were taught and expect what Tim calls
> "normal" rounding:
>
> 2.5 ==> 3
> 3.5 ==> 4
>
> Start dealing with negative numbers and you could make a valid argument
> for rounding either up or down.
>
> Bankers rounding is an attempt to average out the up rounding with the
> down rounding by going to the nearest even number. I believe that this
> is the default rounding for the FPU and so it is what Delphi uses since
> it is the fastest way to perform the calculation.
>
I am a university professor,and I teach my students rounding
is bankers rounding. What you call normal rounding does not
make sense. If this is what you learned in school, you
learned the wrong thing. It is not just for bankers. It is
also for large data evaluations.

The scary part is that round in sql is not correct! If so,
this bug needs fixing!
« Previous PagePage 2 of 3Next Page »
Jump to Page:  1 2 3
Image