CDbl - VBScript
Overview
The CDbl()
command converts a numeric string to a double-precision floating-point number. It is commonly used to ensure consistent data types when working with numbers stored as strings.
Syntax
CDbl(expression)
Parameters:
- expression: A numeric string to be converted to a double-precision floating-point number.
Options/Flags
None.
Examples
Simple Usage:
Dim numString = "123.45"
Dim numDouble = CDbl(numString)
Complex Usage:
Sub CalculateAverage(arrNumbers)
Dim numSum = 0
For Each numString In arrNumbers
numSum += CDbl(numString)
Next
Dim numAvg = numSum / UBound(arrNumbers) + 1
End Sub
Common Issues
- Ensure that the input string represents a valid numeric value. Invalid strings will cause an error.
- The conversion may result in loss of precision for very large or small numbers.
Integration
CDbl()
can be combined with other VB Script functions for more complex tasks, such as:
Str()
to convert a double-precision floating-point number back to a string.Format()
to format the converted number according to a specific format string.
Related Commands
CInt()
CLng()
CSng()