Convert Expression to Single-Precision Method
The Convert Expression to Single-Precision method converts the value that the expression argument contains to a single-precision, floating-point number. It returns this number. Note the following:
After rounding, the result must reside in the range that the single-precision data type allows. If it is not, then an error occurs.
A string that cannot convert to a single-precision number causes a Type Mismatch error.
For more information, see Numeric Data Types That Siebel VB Uses.
Format
CSng(expression)
For information about the arguments that you can use with this method, see Argument That You Can Use with Conversion Methods.
Example
The following example calculates the factorial of a number. For more information, see Exponential Method:
Sub Button_Click
Dim number as Integer
Dim factorial as Double
Dim msgtext As String
number = 25
If number <= 0 then
Exit Sub
End If
factorial = 1
For x = number to 2 step -1
factorial = factorial * x
Next x
'If number <= 35, then its factorial is small enough to
' be stored as a single-precision number
If number< 35 then
factorial = CSng(factorial)
End If
msgtext = "The factorial of " & number & " is " & factorial
End Sub