toBase
Description
Converts a number into its string representation in a specified base.
For example, converting 10 into base 16 results in "a".
Syntax
Like many functions in DataPrime, toBase supports two notations, function and method. These interchangeable forms allow flexibility in how you structure expressions.
- Function notation
- Method notation
toBase(number: number, radix: number): string
(number: number).toBase(radix: number): string
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
number | number | true | The number to convert |
radix | number | true | The base for the conversion (e.g. 16 for hexadecimal) |
Example
Use case: Convert numbers to hexadecimal
Transform a decimal value into a hexadecimal string for representation or further processing.
Example data
{
"val": 10
}
Example query
- Function notation
- Method notation
create val_hex from toBase(val, 16)
create val_hex from val.toBase(16)
Example output
{
"val": 10,
"val_hex": "a"
}