[AccessD] Rounding with CCur conversion

Heenan, Lambert Lambert.Heenan at AIG.com
Fri May 2 08:45:19 CDT 2008


<Another quote from the site>

Banker's rounding: the value is rounded to the nearest even number. Also
known as "Gaussian rounding", and, in German, "mathematische Rundung".
Standard rounding: the value is rounded to the nearest number (be it odd or
even). In German it is known as "kaufmännische Rundung".
VB6's native Round() function uses Banker's rounding, surprising to many
since Standard rounding is more common ...

</Another quote from the site> 

So standard rounding is rounding to the "nearest number"? Take 0.05 and
round to one decimal place. Quick which is nearest 0.1 or 0.0?

Of course there is no nearest number. They are equidistant from 0.05. So how
does "standard rounding" make the choice? Badly I suspect.

Lambert

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gustav Brock
Sent: Friday, May 02, 2008 2:57 AM
To: accessd at databaseadvisors.com
Subject: Re: [AccessD] Rounding with CCur conversion

Hi Asger

First, this:

  CCur(111.11115)

returns here 111.1112 as expected. Don't know why you get a different
result.

Then, the CCur, CInt, CLng and CByte functions perform Banker's rounding
while Int and Fix don't.

Further, Round is known to be buggy, so avoid that for any serious purpose.

If you are interested in rounding and how to optimise this regarding speed
while still being accurate, read on here:

  http://www.xbeat.net/vbspeed/c_Round.htm 

Note that the absolutely simplest (but slowest) method to perform 100%
correct (mathematical) rounding is ... Format!

/gustav

>>> ab-mi at post3.tele.dk 02-05-2008 01:55 >>>
Hi group,

 

I just noticed that the algorithm in VB for rounding seems to be different
for the Round-function and the CCur-function.

The Round-function use "Banker's rounding", also known as "Dutch rounding".
The CCur-function behaves differently:

Round(1.11115,4) --> 1.1112

Round(11.11115,4) --> 11.1112

Round(111.11115,4) --> 111.1112

CCur(1.11115) --> 1.1112

CCur(11.11115) --> 11.1112

CCur(111.11115) --> 111.1111  ?!!

 

What's going on in the last conversion? Is this a bug or does the
CCur-function have a special algorithm?

 

TIA

Asger


--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list