[AccessD] Decimal Data Type

William Hindman wdhindman at dejpolsystems.com
Thu May 15 08:45:24 CDT 2008


...MS knows about the problems and is simply unable or unwilling to fix them 
over multiple versions ...instead of fixes to well known bugs, we get the 
"ribbon" ...something everyone demanded ...on every wish list, eh :(

...google "access bugs decimal" ...Allan Browne has a particularly good 
breakdown on the topic.

William

--------------------------------------------------
From: "Gustav Brock" <Gustav at cactus.dk>
Sent: Thursday, May 15, 2008 9:05 AM
To: <accessd at databaseadvisors.com>
Subject: Re: [AccessD] Decimal Data Type

> Hi Tony (iggy?)
>
> As for the difference, look up the on-line help for range etc.
>
> Why it was added I don't know, but I guess it was to have a data type 
> compatible with Decimal of SQL Server.
>
> I haven't used it myself in a table. William, I think, posted some years 
> ago some nasty examples on errors which the use of the data type could 
> cause.
>
> In VBA it can be necessary for avoiding bit errors when handling very 
> large numbers. I use it in our rounding function posted several times.
>
> Here is another example: Create the Fibonacci sequence of numbers. If Long 
> was used only 46 elements could be calculated:
>
> <code>
> Public Function FibonacciSequenceDec( _
>  ByVal lngElements As Long) _
>  As Variant
>
> ' Build and return array with Fibonacci sequence of numbers.
> ' Count of elements is determined by lngElements.
> ' Max. number returned in array:
> '   50095301248058391139327916261
> '
> ' 2004-10-03. Gustav Brock, Cactus Data, CPH.
>
>  ' Min. index of sequence per definition.
>  Const clngIndexMin  As Long = 0
>  ' Max. possible index of sequence for datatype Decimal.
>  Const clngIndexMax  As Long = 139
>
>  Dim adecSeq()       As Variant
>  Dim lngIndex        As Long
>
>  If lngElements < clngIndexMin Or lngElements > clngIndexMax Then
>    ' Not a valid input.
>  Else
>    ' Build and fill array with the Fibonacci sequence of numbers.
>    ReDim adecSeq(clngIndexMin To lngElements)
>    For lngIndex = clngIndexMin To lngElements
>      If lngIndex < 2 Then
>        ' Values of the first two elements are 0 and 1 per definition.
>        adecSeq(lngIndex) = CDec(lngIndex)
>      Else
>        ' Value is the sum of the two preceding numbers.
>        adecSeq(lngIndex) = CDec(adecSeq(lngIndex - 2)) + 
> CDec(adecSeq(lngIndex - 1))
>      End If
> ''      Debug.Print adecSeq(lngIndex);
>    Next
>  End If
>
>  FibonacciSequenceDec = adecSeq()
>
> End Function
>
> Public Function FibonacciElementDec( _
>  ByVal lngElements As Long) _
>  As Variant
>
> ' Returns the value of element lngElements in the
> ' Fibonacci sequence of numbers.
> ' Max. number returned:
> '   50095301248058391139327916261
> '
> ' 2004-10-03. Gustav Brock, Cactus Data, CPH.
>
>  Const clngIndexMin  As Long = 0
>  Const clngIndexMax  As Long = 139
>
>  Dim decValue        As Variant
>
>  If lngElements < clngIndexMin Or lngElements > clngIndexMax Then
>    ' Not a valid input. Return error.
>    decValue = CDec(-1)
>  Else
>    ' Return last number in sequence in array.
>    decValue = FibonacciSequenceDec(lngElements)(lngElements)
>  End If
>
>  FibonacciElementDec = decValue
>
> End Function
> </code>
>
> /gustav
>
>>>> iggy at nanaimo.ark.com 15-05-2008 14:37 >>>
> Hey Gustav
> How does Decimal differ from Double or Currency and do you know why it
> was added as a data type?  As Edward has confirmed when Access does the
> conversion "you have to hunt through the app and fix things by hand".
>
> That said, Decimal should be avoided as data type in tables as it is known 
> to be buggy. In VBA, however, it can be quite useful.
>
> Just out of curiosity (because I don't know what it is supposed to be
> used for) where would you use it in VBA?
>
> Thanks
>
>
> -- 
> 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