Dim Value As Variant
Value = CDec(1.234)
'Set Value to the smallest possible Decimal value
Value = CDec("0.0000000000000000000000000001")
The Decimal
data-type is only available as a sub-type of Variant
, so you must declare any variable that needs to contain a Decimal
as a Variant
and then assign a Decimal
value using the CDec
function. The keyword Decimal
is a reserved word (which suggests that VBA was eventually going to add first-class support for the type), so Decimal
cannot be used as a variable or procedure name.
The Decimal
type requires 14 bytes of memory (in addition to the bytes required by the parent Variant) and can store numbers with up to 28 decimal places. For numbers without any decimal places, the range of allowed values is -79,228,162,514,264,337,593,543,950,335 to +79,228,162,514,264,337,593,543,950,335 inclusive. For numbers with the maximum 28 decimal places, the range of allowed values is -7.9228162514264337593543950335 to +7.9228162514264337593543950335 inclusive.