This module contains helper functions to work with Numbers.

To use this module, you must import it to your DataWeave code, for example, by adding the line import * from dw::core::Numbers to the header of your DataWeave script.

Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.

Functions

fromBinary

fromBinary(String): Number

Transforms from a binary number into a decimal number.

Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.

Parameters
Name Description

binaryText

The binary number represented in a String.

Example

This example shows how the toBinary behaves with different inputs.

Source
1
2
3
4
5
6
7
8
9
10
11
%dw 2.0
import fromBinary from dw::core::Numbers
output application/json
---
{
    a: fromBinary("-10"),
    b: fromBinary("11111000111010111010110100101011100001001110000011010101100010111101001011100000100010011000011101100101101001111101111010110010010100110010100100000000000000000000000000000000000000000000000000000000000000"),
    c: fromBinary(0),
    d: fromBinary(null),
    e: fromBinary("100"),
}
Output
1
2
3
4
5
6
7
{
  "a": -2,
  "b": 100000000000000000000000000000000000000000000000000000000000000,
  "c": 0,
  "d": null,
  "e": 4
}

fromBinary(Null): Null

Helper function that enables fromBinary to work with null value.

fromHex

fromHex(String): Number

Transforms a hexadecimal number into decimal number.

Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.

Parameters
Name Description

hexText

The hexadecimal number represented in a String.

Example

This example shows how the toBinary behaves with different inputs.

Source
1
2
3
4
5
6
7
8
9
10
11
%dw 2.0
import fromHex from dw::core::Numbers
output application/json
---
{
    a: fromHex("-1"),
    b: fromHex("3e3aeb4ae1383562f4b82261d969f7ac94ca4000000000000000"),
    c: fromHex(0),
    d: fromHex(null),
    e: fromHex("f"),
}
Output
1
2
3
4
5
6
7
{
  "a": -1,
  "b": 100000000000000000000000000000000000000000000000000000000000000,
  "c": 0,
  "d": null,
  "e": 15
}

fromHex(Null): Null

Helper function that enables fromHex to work with null value.

fromRadixNumber

fromRadixNumber(String, Number): Number

Transforms a number in the specified radix into decimal number

Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.

Parameters
Name Description

numberText

The number text.

radix

The radix number.

Example

This example shows how the fromRadixNumber behaves under different inputs.

Source
1
2
3
4
5
6
7
8
%dw 2.0
import fromRadixNumber from dw::core::Numbers
output application/json
---
{
    a: fromRadixNumber("10", 2),
    b: fromRadixNumber("FF", 16)
}
Output
1
2
3
4
{
  "a": 2,
  "b": 255
}

toBinary

toBinary(Number): String

Transforms a decimal number into a binary number.

Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.

Parameters
Name Description

number

The input number.

Example

This example shows how the toBinary behaves with different inputs.

Source
1
2
3
4
5
6
7
8
9
10
11
%dw 2.0
import toBinary from dw::core::Numbers
output application/json
---
{
    a: toBinary(-2),
    b: toBinary(100000000000000000000000000000000000000000000000000000000000000),
    c: toBinary(0),
    d: toBinary(null),
    e: toBinary(2),
}
Output
1
2
3
4
5
6
7
{
  "a": "-10",
  "b": "11111000111010111010110100101011100001001110000011010101100010111101001011100000100010011000011101100101101001111101111010110010010100110010100100000000000000000000000000000000000000000000000000000000000000",
  "c": "0",
  "d": null,
  "e": "10"
}

toBinary(Null): Null

Helper function that enables toBinary to work with null value.

toHex

toHex(Number): String

Transforms a decimal number into a hexadecimal number.

Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.

Parameters
Name Description

number

The input number.

Example

This example shows how toHex behaves with different inputs.

Source
1
2
3
4
5
6
7
8
9
10
11
%dw 2.0
import toHex from dw::core::Numbers
output application/json
---
{
    a: toHex(-1),
    b: toHex(100000000000000000000000000000000000000000000000000000000000000),
    c: toHex(0),
    d: toHex(null),
    e: toHex(15),
}
Output
1
2
3
4
5
6
7
{
  "a": "-1",
  "b": "3e3aeb4ae1383562f4b82261d969f7ac94ca4000000000000000",
  "c": "0",
  "d": null,
  "e": "f"
}

toHex(Null): Null

Helper function that enables toHex to work with null value.

toRadixNumber

toRadixNumber(Number, Number): String

Transforms a decimal number into a number string in other radix.

Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.

Parameters
Name Description

number

The decimal number.

radix

The radix of the result number.

Example

This example shows how the toRadixNumber behaves under different inputs.

Source
1
2
3
4
5
6
7
8
%dw 2.0
import toRadixNumber from dw::core::Numbers
output application/json
---
{
    a: toRadixNumber(2, 2),
    b: toRadixNumber(255, 16)
}
Output
1
2
3
4
{
  "a": "10",
  "b": "ff"
}