Skip to content
Paul Squires edited this page Oct 19, 2026 · 2 revisions

Home › Converting Data Types › CLng

CLng

Converts a number or string to a 32-bit Long, rounding to the nearest; no overflow check.

Syntax

Declare Function CLng ( ByVal expression As datatype ) As Long
Type typename
Declare Operator Cast ( ) As Long
End Type

Parameters

  • expression
  • datatype
  • typename

Description

The CLng function rounds off the decimal part and returns a 32-bit Long value. The function does not check for an overflow, and results are undefined for values which are less than -2 147 483 648 or larger than 2 147 483 647.

The name can be explained as 'Convert to LoNG'.

If the argument is a string expression, it is converted to numeric by using ValInt.

Return Value

A Long value.

Remarks

Usage

result = CLng( numeric expression )

result = CLng( string expression )

result = CLng( user defined type )

Differences from QB

  • The string argument was not allowed in QB

See also

Examples

' Using the CLNG function to convert a numeric value

'Create an LONG variable

Dim numeric_value As Long

'Convert a numeric value

numeric_value = CLng(-300.23)

'Print the result, should return -300

Print numeric_value

Sleep

Category: Converting Data Types
Kind: function


Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.

Clone this wiki locally