CSng Function |
No
CSng(expression)
expression
Use: Required
Data Type: Numeric or String
The range of expression is –3.402823E38 to –1.401298E-45 for negative values, 1.401298E-45 to 3.402823E38 for positive values.
expression cast as a Single data type.
Returns a single-precision number.
expression must evaluate to a numeric value; otherwise, a type mismatch error is generated.
If the value of expression is outside the range of the double data type, an overflow error is generated.
Dim sngMyNumber as Single If IsNumeric(sMyNumber) then sngMyNumber = CSng(sMyNumber) End If
Test that expression evaluates to a number by using the IsNumeric function.
When converting a string representation of a number to a numeric, you should use the data-type conversion functions—such as CSngl—instead of Val, because the data type conversion functions take account of the computer's regional settings. The thousands separator is the most important of these regional settings. For example, if the value of expression is the string 1,234.987, CSng converts it to 1234.987, while Val incorrectly converts it to 1.