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

Home › Converting Data Types › CUInt

CUInt

Converts a number or string to a UInteger, rounding to the nearest; no overflow check.

Syntax

Declare Function CUInt ( ByVal expression As datatype ) As UInteger
Declare Function CUInt<bits> ( ByVal expression As datatype ) As UInteger<bits>
Type typename
Declare Operator Cast ( ) As UInteger
Declare Operator Cast ( ) As UInteger<bits>
End Type

Parameters

  • bits
  • expression
  • datatype
  • typename

Description

The CUInt function rounds off the decimal part and returns a UInteger value, or if a bits value is supplied, an unsigned integer type of the given size.

The function does not check for an overflow; for example, for a 32-bit UInteger results are undefined for values which are less than 0 or larger than 4 294 967 296.

The name can be explained as 'Convert to Unsigned INTeger'.

If the argument is a string expression, it is converted to numeric by using ValUInt or ValULng, depending on the size of the result type.

Return Value

A UInteger or UInteger<bits> containing the converted value.

Remarks

Usage

result = CUInt( numeric expression )

result = CUInt( string expression )

result = CUInt( user defined type )

Dialect Differences

  • Not available in the -lang qb dialect unless referenced with the alias __Cuint.

Differences from QB

  • New to FreeBASIC

See also

Examples

' Using the CUINT function to convert a numeric value

'Create an UNSIGNED INTEGER variable

Dim numeric_value As UInteger

'Convert a numeric value

numeric_value = CUInt(300.23)

'Print the result = 300

Print numeric_value

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