> For the complete documentation index, see [llms.txt](https://docs.wem.io/platform/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wem.io/platform/wemreference/functions/math/tonumber.md).

# ToNumber

{% hint style="info" %}
The **`ToNumber()`** converts a <mark style="color:blue;">value</mark> to a <mark style="color:green;">number</mark>.

This function is NOT SQL compatible. For more information about SQL compatibility, see our [documentation](/platform/wemreference/sql-compatibility.md).

With Modeler v4.4 and Runtimes v5 (August 2025), the ToNumber function got a new overload that accepts a duration and a duration\_unit. Older runtimes will show "invalid expression" when this overload is used.
{% endhint %}

{% hint style="warning" %}
Note: this function uses the language setting of a portal when converting text.
{% endhint %}

{% hint style="success" %}
Returns the number converted from `text` or a unit from `date`.\
Returns <mark style="color:red;">`Invalid expression`</mark> when `text` is not a number, or when `reference` is not a valid RowId, or when `date` is not a valid date value or `unit` is not a valid date unit.
{% endhint %}

### Syntax

<details>

<summary><code>ToNumber(</code><mark style="color:blue;"><code>text</code></mark><code>)</code></summary>

`ToNumber("1.34")`\
*=> 1.34*

`ToNumber("a123b456")`\
*=> Invalid expression*

`ToNumber(unknowntext)`\
*=> unknown*

</details>

<details>

<summary><code>ToNumber(</code><mark style="color:blue;"><code>reference</code></mark><code>)</code></summary>

`ToNumber([reference-field to currentrow of a list])`\
*=> \[the numeric ID value of the current row]*

</details>

<details>

<summary><code>ToNumber(</code><mark style="color:blue;"><code>date, date_unit</code></mark><code>)</code></summary>

`ToNumber(date(2015,9,26,15,46,29), day)`\
*=> 269*

`ToNumber()`\
*=> Invalid expression*

</details>

<details>

<summary><code>ToNumber(</code><mark style="color:blue;"><code>duration, duration_unit</code></mark><code>)</code></summary>

`ToNumber(ToDuration("0.00:02:14.12"), millisecond)`\
*=> 134120*

<mark style="color:red;">This implementation only works on Kubernetes Runtimes version 5 and up!</mark>

*Duration units:*\
`day` - results in the total number of days\
`hour` - results in the total number of hours\
`minute` - results in the total number of minutes\
`second` - results in the total number of seconds\
`millisecond` - results in the total number of milliseconds

</details>

### Parameters

<table><thead><tr><th width="150">Name</th><th width="150">Type</th><th width="150" align="center">Required</th><th width="248.15953250810662">Description</th><th data-hidden>Required?</th></tr></thead><tbody><tr><td><mark style="color:blue;"><code>text</code></mark></td><td>text</td><td align="center"><span data-gb-custom-inline data-tag="emoji" data-code="2611">☑️</span></td><td>a text containing a number.</td><td>yes</td></tr><tr><td><mark style="color:blue;"><code>reference</code></mark></td><td>reference</td><td align="center"><span data-gb-custom-inline data-tag="emoji" data-code="2611">☑️</span></td><td>reference field, holding a rowid of a list.</td><td></td></tr><tr><td><mark style="color:blue;"><code>date</code></mark></td><td>date</td><td align="center"><span data-gb-custom-inline data-tag="emoji" data-code="2611">☑️</span></td><td>a date.</td><td>yes</td></tr><tr><td><mark style="color:blue;"><code>unit</code></mark></td><td>date-unit</td><td align="center"><span data-gb-custom-inline data-tag="emoji" data-code="2611">☑️</span></td><td>the <a href="https://wem.io/documentation/reference/functions/quickreference/datatypes#datetime-unit">unit</a> that is retrieved from <code>date</code>.</td><td></td></tr><tr><td><mark style="color:blue;"><code>duration</code></mark></td><td>duration</td><td align="center"><span data-gb-custom-inline data-tag="emoji" data-code="2611">☑️</span></td><td>a duration value.<br><mark style="color:red;">supported from runtime v5</mark><br><mark style="color:red;">invalid expression in older runtimes</mark>.</td><td></td></tr><tr><td><mark style="color:blue;"><code>duration_unit</code></mark></td><td>duration-unit</td><td align="center"><span data-gb-custom-inline data-tag="emoji" data-code="2611">☑️</span></td><td><em>Duration units:</em><br><code>day</code> - results in the total number of days<br><code>hour</code> - results in the total number of hours<br><code>minute</code> - results in the total number of minutes<br><code>second</code> - results in the total number of seconds<br><code>millisecond</code> - results in the total number of milliseconds</td><td></td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.wem.io/platform/wemreference/functions/math/tonumber.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
