Returns the expression converted to a decimal variant-subtype (Variant).

expressionThe expression to evaluate and convert to a decimal.

* The Decimal data type is a sub type of the Variant data type.
* The "expression" can be any number between -7.9 E28 and +7.9 E28
* This function always returns a variant whose value has been converted to a Decimal subtype.
* There does not actually exist a Decimal data type although it is possible to have a Variant data type, whose subtype is Decimal.
* An overflow error will occur if the value is out of range.
* For the Microsoft documentation refer to

CDec(15.75) = 15.75 
CDec(15) = 15
CDec(8E +30) = "Overflow error"

Debug.Print CDec("-100") '-100
Debug.Print CDec("100-") '-100

Dim lPrice As Long
lPrice = 12.75
? TypeName(CDec(lPrice)) = "Decimal"

© 2020 Better Solutions Limited. All Rights Reserved. © 2020 Better Solutions Limited Top