Number methods are called on number values.
Use parentheses when the method target is a numeric literal.
(123).to_string();
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
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();
Converts a number to an unsigned 32-bit integer value.
| Item | Description |
|---|---|
| Syntax | `number.to_uint()` |
| Arguments | none |
| Returns | number |
Example:
(255).to_uint();
Converts a number to a signed 8-bit integer value.
| Item | Description |
|---|---|
| Syntax | `number.to_s8()` |
| Arguments | none |
| Returns | number |
Example:
(127).to_s8();
Converts a number to an unsigned 8-bit integer value.
| Item | Description |
|---|---|
| Syntax | `number.to_u8()` |
| Arguments | none |
| Returns | number |
Example:
(255).to_u8();
Converts a number to a signed 16-bit integer value.
| Item | Description |
|---|---|
| Syntax | `number.to_s16()` |
| Arguments | none |
| Returns | number |
Example:
(32000).to_s16();
Converts a number to an unsigned 16-bit integer value.
| Item | Description |
|---|---|
| Syntax | `number.to_u16()` |
| Arguments | none |
| Returns | number |
Example:
(65535).to_u16();
Converts a number to a signed 32-bit integer value.
| Item | Description |
|---|---|
| Syntax | `number.to_s32()` |
| Arguments | none |
| Returns | number |
Example:
(123456).to_s32();
Converts a number to an unsigned 32-bit integer value.
| Item | Description |
|---|---|
| Syntax | `number.to_u32()` |
| Arguments | none |
| Returns | number |
Example:
(123456).to_u32();
Converts a number to a signed 64-bit integer value.
| Item | Description |
|---|---|
| Syntax | `number.to_s64()` |
| Arguments | none |
| Returns | number |
Example:
(123456789).to_s64();
Converts a number to an unsigned 64-bit integer value.
| Item | Description |
|---|---|
| Syntax | `number.to_u64()` |
| Arguments | none |
| Returns | number |
Example:
(123456789).to_u64();
Converts a number to decimal string form.
| Item | Description |
|---|---|
| Syntax | `number.to_string()` |
| Arguments | none |
| Returns | string |
Example:
(123.45).to_string();
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}');
Converts a number to hexadecimal string form.
| Item | Description |
|---|---|
| Syntax | `number.to_hex()` |
| Arguments | none |
| Returns | string |
Example:
(255).to_hex(); // FF
Converts a number to binary string form.
| Item | Description |
|---|---|
| Syntax | `number.to_bin()` |
| Arguments | none |
| Returns | string |
Example:
(5).to_bin();
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'
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); // '-----'
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
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