CSng

Coerces an expression to a Single.

Syntax: CSng( expression )

expression
required Any valid string or numeric expression in the Single range — -3.402823E38 to -1.401298E-45 for negative values, and 1.401298E-45 to 3.402823E38 for positive values.

The return type is Single. If expression is outside the range of a Single, a run-time error occurs.

Use CSng instead of Val to provide internationally aware conversions from a string to a numeric type.

Example

This example uses the CSng function to convert values to a Single.

Dim MyDouble1, MyDouble2, MySingle1, MySingle2
' MyDouble1, MyDouble2 are Doubles.
MyDouble1 = 75.3421115: MyDouble2 = 75.3421555
MySingle1 = CSng(MyDouble1)              ' MySingle1 contains 75.34211.
MySingle2 = CSng(MyDouble2)              ' MySingle2 contains 75.34216.

See Also

License: CC-BY-4.0 Code license: MIT Attribution: VBA-Docs