---
schema_version: "1"
id: 2e9fe25de40b09feb8c27616f3a62c70c635a5d4d85d72404accb5c6b0e6f760
title: toNumberOrNull
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.9/dw-coercions-functions-tonumberornull.md
canonical_url: https://docs.mulesoft.com/dataweave/2.9/dw-coercions-functions-tonumberornull
source_site: docs.mulesoft.com
content_type: documentation
content_hash: fd47202795fce83399534c3333bacc1855be827a401ceb206159fb7a08f851a0
description: MuleSoft Documentation Site
release: "2.9"
latest: false
---
---
product: DataWeave
version: 2.9
---

# toNumberOrNull

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## toNumberOrNull(str: String, formatters: Array<Formatter>): Number | Null

Transforms a `String` value into a `Number` value using the first `Formatter` that matches with the
given value to transform.

If none of the `Formatter` matches with the given value, the function returns a `null` value.

_Introduced in DataWeave version 2.5.0._

### Parameters

<table><colgroup><col> <col> <col></colgroup><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p><code>str</code></p></td><td><p>String</p></td><td><p>The <code>String</code> value to transform into a <code>Number</code> value.</p></td></tr><tr><td><p><code>formatters</code></p></td><td><p>Array&lt;Formatter&gt;</p></td><td><p>The <code>array</code> of formatting to use on the <code>Number</code> value.</p></td></tr></tbody></table>

### Example

This example shows how `toNumberOrNull` behaves with different inputs. It produces output in the
`application/dw` format.

#### Source

```DataWeave
%dw 2.0
import * from dw::util::Coercions
output application/dw
---
{
  a: toNumberOrNull("0.005", [{format: "seconds"}, {format: ".00"}]),
  b: toNumberOrNull("0.005", [{format: "seconds"}])
}
```

#### Output

```DataWeave
{
  a: 0.005 as Number {format: ".00"},
  b: null
}
```
