%dw 2.0
import * from dw::util::Coercions
output application/json
---
{
epoch: toNumber(|2015-10-01T23:57:59Z|),
millis: toNumber(|2015-10-01T23:57:59Z|, "milliseconds")
}
toNumber
toNumber(dateTime: DateTime, unit: MillisOrSecs | Null = null): Number
A variant of toNumber
that transforms a DateTime
value
into a number of seconds or milliseconds, depending on the
selected unit.
Introduced in DataWeave version 2.4.0.
Parameters
Name | Description |
---|---|
|
The |
|
The unit of time ( |
toNumber(period: Period, unit: PeriodUnits | Null = null): Number
A variant of toNumber
that transforms a Period
value
into a number of hours, minutes, seconds, milliseconds
or nanoseconds (nanos
).
Introduced in DataWeave version 2.4.0.
Parameters
Name | Description |
---|---|
|
The |
|
The unit to apply to the specified |
toNumber(value: String | Key, format: String | Null = null, locale: String | Null = null): Number
A variant of toNumber
that transforms a String
or Key
value into
a Number
value and that accepts a format and locale.
Introduced in DataWeave version 2.4.0.
Parameters
Name | Description |
---|---|
|
The |
|
Optional formatting to apply to the |
|
Optional ISO 3166 country code to use, such as |
Example
This example shows how toNumber
behaves with different inputs.
Source
%dw 2.0
import * from dw::util::Coercions
var myKey = keysOf({"123" : "myValue"})
output application/json
---
{
"default": toNumber("1.0"),
"withFormat": toNumber("0.005",".00"),
"withLocal": toNumber("1,25","#.##","ES"),
"withExtraPlaceholders": toNumber("5.55","####.####"),
"keyToNumber": toNumber(myKey[0])
}