例: CSng 関数

例 1

' Convert string to single
' Display value and data type
Dim nvar As Variant
Dim nstr As String
nstr = Inputbox("Number", "Enter any number", "0")
If Isnumeric(nstr) Then
	nvar = Csng(nstr)
	Messagebox nvar,, Typename(nvar)
Else
	Messagebox nstr,, "Not a number"
End Sub

例 2

' Convert a Double value by rounding to nearest Single.
Dim x As Double
x# = 1.70800003057064E+24
Print CSng(x#)             ' Prints 1.708E+24