# toNumber

> This document is the Markdown version of [valibot.dev/api/toNumber/](https://valibot.dev/api/toNumber/). For the complete documentation index, see [llms.txt](https://valibot.dev/llms.txt).

Creates a to number transformation action.

```ts
const Action = v.toNumber<TInput, TMessage>(message);
```

## Generics

- `TInput` `extends any`
- `TMessage` `extends ErrorMessage<ToNumberIssue<TInput>> | undefined`

## Parameters

- `message` `TMessage`

### Explanation

With `toNumber` you can transform the input to a number. If the input cannot be transformed, you can use `message` to customize the error message.

## Returns

- `Action` `ToNumberAction<TInput, TMessage>`

## Examples

The following examples show how `toNumber` can be used.

### Number schema

Schema to validate a string and transform it to a number.

```ts
const NumberSchema = v.pipe(v.string(), v.toNumber());
```

## Related

The following APIs can be combined with `toNumber`.

### Schemas

[`any`](/api/any.md), [`bigint`](/api/bigint.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`null`](/api/null.md), [`string`](/api/string.md), [`unknown`](/api/unknown.md)

### Methods

[`pipe`](/api/pipe.md)

### Utils

[`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md)
