Q(uick)BASIC Function: CSNG

Quick View

CSNG

A conversion function that converts a numeric expression to a single-precision value

Worth knowing

Useful and cross-version information about the programming environments of QBasic and QuickBasic.

Syntax
  • CDBL (numeric-expression)
  • CSNG (numeric-expression)
Description/Parameter(s)
numeric-expression Any numeric expression.
Example
PRINT 1 / 3, CDBL(1 / 3) 'Output is: .3333333 .3333333333333333 PRINT CSNG(975.3421515#) 'Output is: 975.3422
Syntax
  • CSNG(numeric-expression)
Description/Parameter(s)

The CSNG function has the same effect as assigning numeric-expression to a single-precision variable.

CSNG rounds the value, if necessary, before converting it.

Example

The following example shows how CSNG rounds before converting the value:

A#=975.3421115# B#=975.3421555# PRINT A#; CSNG(A#); B#; CSNG(B#)

Sample Output:

975.3421115 975.3421 975.3421555 975.3422
Syntax
  • CSNG(numeric-expression)
Description/Parameter(s)

Usage Notes

  • The CSNG function has the same effect as assigning numeric-expression to a single-precision variable.
  • CSNG rounds the value, if necessary, before converting it.
Example

This example uses the CSNG funcion to round values before converting them to single precision.

A# = 975.3421115# B# = 975.3421555# PRINT A#; CSNG(A#); B#; CSNG(B#)

Sample Output:

975.3421115 975.3421 975.3421555 975.3422