Skip to content

toBase - Change base of numerical value

The toBase function will render out a string representation of a number.

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 into its string representation
radixnumbertrueThe base for the new stringified number. e.g hexidecimal is 16

Example - Converting a number to hexidecimal

Consider the following document:

{
    "val": 10
}

If we wish to convert val into a hex representation, we can use toBase:

create val_hex from toBase(val, 16)
create val_hex from val.toBase(16)

This results in the following document:

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

Try it yourself

Open the Explore screen in Coralogix and paste this query:

create val from 10
| create val_hex from val.toBase(16)