Help Center
Help CenterFreeBASIC

CSngfunction

Converts numeric or string expression to Single precision floating point

Converting Data Typesfunctiondocumented

Syntax

Declare Function CSng ( ByVal expression As datatype ) As Single
Type typename
Declare Operator Cast ( ) As Single
End Type

Parameters

NameDescription
expressiona numeric, string, or pointer expression to cast to a Single value
datatypeany numeric, string, or pointer data type
typenamea user defined type

Return value


A Single precision value.

Description


The CSng function returns a 32-bit Single value. The function does not check for an overflow, so be sure not to pass a value outside the representable range of the Single data type. The name can be explained as 'Convert to SiNGle'.

If the argument to CSng is a string expression, it is first converted to numeric by using Val.

Remarks

Usage


result = CSng( numeric expression )
result = CSng( string expression )
result = CSng( user defined type )

Differences from QB


  • The string argument was not allowed in QB

See also


Example


' Using the CSNG function to convert a numeric value



'Create an SINGLE variable

Dim numeric_value As Single



'Convert a numeric value

numeric_value = CSng(-12345.123)



'Print the result, should return -12345.123

Print numeric_value

Sleep


Reference

  • Documented in KeyPgCsng.html