Sidebar

Home



Expressions V4


Tutorials

How-To

Reference

  Lexical basics
  Type system
  Variables and assignment
  Operators
  Expression rules
  Control flow
  Functions
  Built-in functions
   None and NaN
   Arithmetic
   Algebra
   Logarithmic and Exponential
   Trigonometric
   Rounding and Centering
   Strings
   Output, Formatting, Clipboard, and Errors
   Dialog Functions
   Platform and Paths
  Methods and properties
  Built-in methods
   Common Value Methods
   Number Methods
   String Basic Methods
   String Slice Methods
   String Parsing Methods
   String Formatting Methods
   String Regex Methods
   String Trim and Case Methods
  Objects
  Built-in objects
   Global objects
    settings
    controller
    session
    python
   Collections
    array
    map
    bytes
   File Format I/O
    image_data
    image_stream
   Utils
    crypto
    timer
   Comm
    serial
   Dialogs
    file_open
    file_save
    msg_ok
    msg_ok_cancel
    msg_yes_no
    msg_password
   GUI objects
    window
    panel
    group
    splitpanel
    label
    textbutton
    drawablebutton
    togglebutton
    togglegroup
    textinput
    textedit
    numinput
    slider
    combobox
    listbox
    progressbar
    led
    separator
    menu
    image
    snake
  Classes and user-defined objects
  Include system
  Error model
  Execution model and sessions
  Host integration
  Limits and performance
  Formal reference
  Glossary

Cookbook

exprv4:reference:methods:number_methods



Number Methods

Number methods are called on number values.

Use parentheses when the method target is a numeric literal.

(123).to_string();

to_bool()

Converts a number to a boolean-style numeric value.

Item Description
Syntax `number.to_bool()`
Arguments none
Returns number

Example:

(0).to_bool();        // false
(5).to_bool();        // true

to_int()

Converts a number to a signed 32-bit integer value.

Item Description
Syntax `number.to_int()`
Arguments none
Returns number

Example:

(12.7).to_int();

to_uint()

Converts a number to an unsigned 32-bit integer value.

Item Description
Syntax `number.to_uint()`
Arguments none
Returns number

Example:

(255).to_uint();

to_s8()

Converts a number to a signed 8-bit integer value.

Item Description
Syntax `number.to_s8()`
Arguments none
Returns number

Example:

(127).to_s8();

to_u8()

Converts a number to an unsigned 8-bit integer value.

Item Description
Syntax `number.to_u8()`
Arguments none
Returns number

Example:

(255).to_u8();

to_s16()

Converts a number to a signed 16-bit integer value.

Item Description
Syntax `number.to_s16()`
Arguments none
Returns number

Example:

(32000).to_s16();

to_u16()

Converts a number to an unsigned 16-bit integer value.

Item Description
Syntax `number.to_u16()`
Arguments none
Returns number

Example:

(65535).to_u16();

to_s32()

Converts a number to a signed 32-bit integer value.

Item Description
Syntax `number.to_s32()`
Arguments none
Returns number

Example:

(123456).to_s32();

to_u32()

Converts a number to an unsigned 32-bit integer value.

Item Description
Syntax `number.to_u32()`
Arguments none
Returns number

Example:

(123456).to_u32();

to_s64()

Converts a number to a signed 64-bit integer value.

Item Description
Syntax `number.to_s64()`
Arguments none
Returns number

Example:

(123456789).to_s64();

to_u64()

Converts a number to an unsigned 64-bit integer value.

Item Description
Syntax `number.to_u64()`
Arguments none
Returns number

Example:

(123456789).to_u64();

to_string()

Converts a number to decimal string form.

Item Description
Syntax `number.to_string()`
Arguments none
Returns string

Example:

(123.45).to_string();

to_string(format)

Converts a number to a string using a format string.

Argument Type Description
`format` string Number format string used by the host formatter.

Returns: string.

Example:

(12.3456).to_string('{:.2f}');

to_hex()

Converts a number to hexadecimal string form.

Item Description
Syntax `number.to_hex()`
Arguments none
Returns string

Example:

(255).to_hex();       // FF

to_bin()

Converts a number to binary string form.

Item Description
Syntax `number.to_bin()`
Arguments none
Returns string

Example:

(5).to_bin();

chr()

Converts the low byte of a number to a one-character string.

Item Description
Syntax `number.chr()`
Arguments none
Returns string

Example:

(65).chr();           // 'A'

chr(count)

Converts the low byte of a number to a repeated character string.

Argument Type Description
`count` number Number of characters to return. Values less than or equal to zero return an empty string.

Returns: string.

Example:

(45).chr(5);          // '-----'

bit(index)

Reads one bit from an integer-like number.

Argument Type Description
`index` number Bit index from `0` to `63`.

Returns: boolean-style number.

Example:

(5).bit(0);           // true
(5).bit(1);           // false

bit(index, value)

Returns a copy of the number with one bit changed.

Argument Type Description
`index` number Bit index from `0` to `63`.
`value` any Converted to bool. True sets the bit; false clears it.

Returns: number.

Example:

(4).bit(0, true);     // 5
(5).bit(2, false);    // 1

Previous: Common Value Methods

Next: String Basic Methods

exprv4/reference/methods/number_methods.txt · Last modified: by 127.0.0.1

Page Tools