CSng Function
Returns the expression, which has been converted toSingleSubtypeVariant。
CSng(expression)
expressionParameters are any valid expressions.
illustrate
Typically, code can be written using subtype conversion functions to show that the results of certain operations should be represented as specific data types, rather than the default types. For example, in the case of currency or integer operation, useCDblorCSngEnforce double or single precision operations.
CSngFunctions are used to perform from other data types toSingleInternationally recognized format conversion for subtypes. For example, the recognition of decimal separators (such as thousands) depends on the system's locale settings.
ifexpressionAn error occurs outside the scope allowed by the Single subtype.
The following example usesCSngFunction converts values toSingle:
Dim MyDouble1, MyDouble2, MySingle1, MySingle2 ' MyDouble1, MyDouble2
It's a double precision value。MyDouble1 = 75.3421115: MyDouble2 = 75.3421555
MySingle1 = CSng(MyDouble1) ' MySingle1
Include75.34211
。MySingle2 = CSng(MyDouble2) ' MySingle2
Include75.34216
。