---
schema_version: "1"
id: 288b06c886a54e8fb0f47625d268fb0acef229ed9a89f350f28c7a4e58a89082
title: toNumberOrNull
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/latest/dw-coercions-functions-tonumberornull.md
canonical_url: https://docs.mulesoft.com/dataweave/latest/dw-coercions-functions-tonumberornull
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 21824e68c6194453ef8b3d7c280a6e8a30e36a0e2f1e041dc1566da83ffac844
description: MuleSoft Documentation Site
release: "2.13"
latest: true
---
---
product: DataWeave
version: 2.13
is-latest-version: true
---

# 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
}
```
