Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Fnumber%2Ftobase.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Fnumber%2Ftobase.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# `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](https://docs-docusaurus.kinsta.page/dataprime/language-reference/functions-reference/.md),<!-- --> **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"

}
```
