Q(uick)BASIC Function: CLNG

Quick View

CLNG

A conversion function that converts a numeric expression to a long (4-byte) integer by rounding the fractional part of the expression

Worth knowing

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

Syntax
  • CINT(numeric-expression)
  • CLNG(numeric-expression)
Description/Parameter(s)

CINT rounds a numeric expression to an integer. CLNG rounds a numeric expression to a long (4-byte) integer.

numeric-expression For CINT, any numeric expression in the range -32,768 through 32,767.
For CLNG, any numeric expression in the range -2,147,483,648 through 2,147,483,647.
Example
PRINT CINT(12.49), CINT(12.51) 'Output is: 12 13 PRINT CLNG(338457.8) 'Output is: 338458
Syntax
  • CLNG(numeric-expression)
Description/Parameter(s)

If numeric-expression is not in the range -2,147,483,648 to 2,147,483,647, the function produces an error message that reads "Overflow."

Example

The following example shows how CLNG rounds before converting the number:

A=32767.45 B=32767.55 PRINT CLNG(A); CLNG(B)

Sample Output:

32767 32768
Syntax
  • CLNG(numeric-expression)
Description/Parameter(s)
numeric-expression Any numeric expression between -2,147,483,648 and 2,147,483,647, inclusive.
Returns A long integer.
  • If numeric-expression is not between -2,147,483,648 and 2,147,483,647, inclusive, BASIC generates the error message, "Overflow."
Example

This example uses the CLNG function to round a number before converting it to a long integer.

A = 32767.45 B = 32767.55 PRINT CLNG(A); CLNG(B)

Sample Output:

32767 32768