> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://v3.viem.sh/api/mcp` to find what you need.

# Hex.toNumber

:::info
`Hex.toNumber` is a re-export of ox's [`Hex.toNumber`](https://oxlib.sh/api/Hex/toNumber). Refer to the ox documentation for the full reference.
:::

Decodes a [`Hex.Hex`](/docs/utilities/hex/types#hex) value into a number.

## Imports

```ts
import { Hex } from 'viem/utils'
```

## Examples

```ts twoslash
// @noErrors
import { Hex } from 'viem/utils'

Hex.toNumber('0x1a4')
// @log: 420

Hex.toNumber(
  '0x00000000000000000000000000000000000000000000000000000000000001a4',
  { size: 32 }
)
// @log: 420
```

## Definition

```ts
function toNumber(
  hex: Hex,
  options?: toNumber.Options,
): number
```

## Parameters

### hex

* **Type:** `Hex`

The [`Hex.Hex`](/docs/utilities/hex/types#hex) value to decode.

### options

* **Type:** `toNumber.Options`
* **Optional**

Options.

## Return Type

The decoded number.

`number`
