[AccessD] Rounding Error - A2K

Gustav Brock Gustav at cactus.dk
Fri Dec 11 13:16:07 CST 2009


Hi Reuben

Well, that's the tiny details. To know about these or at least to be able to smell a potential danger before it pops forward is what makes you stand out from the script kiddies.

/gustav


>>> accessd at gfconsultants.com 11-12-2009 19:56 >>>
I need the result to be currency so everything is working perfectly.
I guess it just befuddles me that you could take a currency and if you
divide it by 100 it would change back to double.  In my mind, it simply
leaves it as currency and you lose two decimals.

Reuben Cummings
GFC, LLC
812.523.1017


> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com 
> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of 
> Gustav Brock
> Sent: Friday, December 11, 2009 12:26 PM
> To: accessd at databaseadvisors.com 
> Subject: Re: [AccessD] Rounding Error - A2K
> 
> 
> Hi Reuben
> 
> The result of this:
> 
>   CurAmount * CCur(100 * SngPercentage) / 100
> 
> is a double. That's why I converted it to currency:
> 
>   CCur(CurAmount * CCur(100 * SngPercentage) / 100)
> 
> but, of course, that will round to four decimals.
> If you really need six decimals for the result, you have 
> three options:
> 
> 1. Leave it as a double. For later calculations, multiply by 
> 100, calculate, divide by 100.
> 
> 2. Multiply the result by 100 by leaving out the dividing by 100:
> 
>   CurAmount * CCur(100 * SngPercentage)
> 
> For later calculations, divide the result by 100.
> 
> 3. Convert to decimal. This is a subtype of variant and is 
> quite useful for interim calculations meaning results you 
> need in your code without storing them to a table.
> Newer version of Access features the decimal data type for 
> tables, but it is known to be buggy in a dangerous and 
> destructive way, so don't.
> 
> /gustav
> 
> 
> >>> accessd at gfconsultants.com 11-12-2009 18:01 >>>
> My question is...
> What data type is the result of your equation?
> 
> I understant multiplying by 100 before converting to Currency in order to
> maintain all the decimals.
> However, when you divide by 100 what's the result?  If it stayed currency
> wouldn't you lose two of the decimals?
> 
> Reuben Cummings
> GFC, LLC
> 812.523.1017






More information about the AccessD mailing list