Skip to content

Cushort

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

Home › Converting Data Types › CUShort

CUShort

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

Syntax

Declare Function CUShort ( ByVal expression As datatype ) As UShort
Type typename
Declare Operator Cast ( ) As UShort
End Type

Parameters

  • expression
  • datatype
  • typename

Description

The CUShort function rounds off the decimal part and returns a 16-bit UShort value. The function does not check for an overflow, and results are undefined for values which are less than 0 or larger than 65 535.

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

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

Return Value

A UShort value.

Remarks

Usage

result = CUShort( numeric expression )

result = CUShort( string expression )

result = CUShort( user defined type )

Dialect Differences

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

Differences from QB

  • New to FreeBASIC

See also

Examples

' Using the CUSHORT function to convert a numeric value

'Create an USHORT variable

Dim numeric_value As UShort

'Convert a numeric value

numeric_value = CUShort(36000.4)

'Print the result, should return 36000

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