# `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://coralogix.com/docs/dataprime/language-reference/functions-reference/index.md), **function** and **method** notation. These interchangeable forms allow flexibility in how you structure expressions.

```dataprime
toBase(number: number, radix: number): string
```

```dataprime
(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

```json
{
    "val": 10
}
```

### Example query

```dataprime
create val_hex from toBase(val, 16)
```

```dataprime
create val_hex from val.toBase(16)
```

### Example output

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