expression(required; Numeric or String)
The range is +/-79,228,162,514,264,337,593,543,950,335 for numbers with no decimal places. The range is +/-7.9228162514264337593543950335 for numbers with up to 28 decimal places. The smallest possible nonzero number is 0.0000000000000000000000000001.
expression cast as a Decimal type
This function casts
expression as a
If the value of
expression is outside the
range of the Decimal data type, an overflow error is generated.
expression must evaluate to a numeric
value; otherwise a type-mismatch error is generated. To prevent this,
it can be tested beforehand with the IsNumeric
Dim decMyNumber As Decimal If IsNumeric(sMyNumber) then decMyNumber = CDec(sMyNumber) End If
The Decimal data type replaces the VB 6 Currency data type and is appropriate for very large, very small, or very high precision numbers.
Use IsNumeric to test whether
expression evaluates to a number.
When converting a string representation of a number to a numeric, you should use the data type conversion functions — such as CDec — instead of Val, because the data type conversion functions take account of the system’s regional settings. In particular, the CDec function recognizes the thousands separator if it is encountered in the string representation of a number. For example, if the user inputs the value 1,827,209.6654, ...