CBYT, CCUR, CCUX, CDBL, CDWD, CEXT, CINT, CLNG, CQUD, CSNG, and CWRD functions

Purpose

Convert a value to specific variable type.

Syntax

bytevar?          = CBYT(numeric_expression)

currencyvar@      = CCUR(numeric_expression)

currencyextvar@@  = CCUX(numeric_expression)

doublevar#        = CDBL(numeric_expression)

doublewordvar???  = CDWD(numeric_expression)

extendedvar##     = CEXT(numeric_expression)

integervar%       = CINT(numeric_expression)

longintvar&       = CLNG(numeric_expression)

quadintvar&&      = CQUD(numeric_expression)

singlevar!        = CSNG(numeric_expression)

wordvar??         = CWRD(numeric_expression)

Remarks

Each of these functions converts a numeric expression to a particular variable type.  In each case, numeric_expression must be within the legal range for the result type.  The numeric_expression will be rounded if necessary.

These conversion functions are rarely needed as PowerBASIC automatically performs any necessary conversions when executing an assignment statement or passing parameters.  For example:

e% = f#

is equivalent to:

e% = CINT(f#)

In the case of the functions that convert to integral-class values, the fractional part of the number is rounded. If the fractional part is exactly .5 then it rounds to the nearest even integral value. For example, CINT(1.5) returns 2, CINT(.5) returns 0, and CLNG(-0.6) returns -1.

Restrictions

CSNG limit string display to 7 significant digits.

See also

CEIL, CVI and associated functions, FIX, INT, MKI$ and associated functions

Example

' Calculate CINT for a series of values

FOR I! = 2.4! TO 2.65! STEP 0.05!
  x$ = FORMAT$(I!, "0.00") + " is" + STR$(CINT(I!))
NEXT I!

Result

2.40 is 2

2.45 is 2

2.50 is 2

2.55 is 3

2.60 is 3

2.65 is 3