Skip to content

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 notation. These interchangeable forms allow flexibility in how you structure expressions.

toBase(number: number, radix: number): string
(number: number).toBase(radix: number): string

Arguments

NameTypeRequiredDescription
numbernumbertrueThe number to convert
radixnumbertrueThe 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.

{
    "val": 10
}
create val_hex from toBase(val, 16)
create val_hex from val.toBase(16)

Output

{
    "val": 10,
    "val_hex": "a"
}