The functions were created to:

  • speed up the creation of your integrations even more

  • decrease the complexity of your pipelines

  • simplify data conversions and transformations during the flow of your pipelines

The numerical functions treat numbers and are available for components that support Double Braces expressions. To know how to provide information to the components using this resource, click here.

FORMATNUMBER

By using Double Braces, you can combine the function with the access to the input JSON element of a component.

The function can be applied to convert a string or numerical element type into a format defined by the second argument. The second argument specifies the destination format (including the possibility of treating your locale).

Syntax

FORMATNUMBER(value, "formatDestination", "localeDest"?)

The items indicated with "?" can be defined with the null value.

  • value: the number that will be converted. It can be a string or number. Use string preferably.

  • formatDestination: the format informed in the number treatment.

  • localeDest representing locale must be considered for the number generation. If the localeDest isn't defined, en-us will be considered.

  • rounding: the rounding type which will be used. They can be UP, DOWN, CEILING, FLOOR, HALF_UP, HALF_DOWN, and HALF_EVEN. The function uses the pattern HALF_EVEN.

Input value:

{
"number": 123456.9123,
"negative": -987.123
}

Conversion examples:

{
"number-US":{{ FORMATNUMBER( message.number, "###,###.###", "us-EN") }},

"number-rounding":{{ FORMATNUMBER( TOSTRING(message.numero), "###,###.###", "us-EN", "CEILING") }},

"number-BR":{{ FORMATNUMBER( message.number, "###,###.###", "pt-BR") }},

"number-BR-1":{{ FORMATNUMBER( message.number, "###,###.#", "pt-BR") }},

"number-positive-BR-a": {{ FORMATNUMBER( message.number, "'+'###,###.###;'-'###,###.###", "pt-BR") }},

"number-negative-BR": {{ FORMATNUMBER( message.negative, "###,###.###'C';###,###.###'D'", "pt-BR") }},

"number-negative-BR-a": {{ FORMATNUMBER( message.negative, "'+'###,###.###;'-'###,###.###", "pt-BR") }}
}

Other formatDestination examples:

Pattern Number Formatted String

###.### 123.456 123.456

###.# 123.456 123.5

###,###.## 123456.789 123,456.79000.

### 9.95 009.95

##0.### 0.95 0.95

TODOUBLE

By using Double Braces, you can combine the function with the access to the input JSON element of a component.

The function is applied to return the double value of a whole number.

Syntax

TODOUBLE(num1)

{

“a”: 12

}

{

"doub": {{ TODOUBLE( message.a ) }}

}

The return of this function will be 12.0.

TOINT

By using Double Braces, you can combine the function with the access to the input JSON element of a component.

The function is applied to return the whole number of a double number.

Syntax

TOINT(num1)

{

“a”: 12.345

}

{

"int": {{ TOINT( message.a ) }}

}

The return of this function will be 12.

TOLONG

By using Double Braces, you can have a LONG-type value returned from a number. It's possible to receive not only a string, but also a number as input parameter.

Syntax

TOLONG(num1)

{

“a”: 12.345

}

{

"long": {{ TOLONG( message.a ) }}

}

The return of this function will be 12.

TONUMBER

This function allows you to convert a string value to a numeric value based on its source format and locale.

Syntax

TONUMBER(string, formatSource, localeSource?, asInteger?)

The parameters indicated with "?" are optionals.

  • string: the string to be converted.

  • formatSource: source format of the string. Eg.: "###.###", "###.#", "###,###.##".

  • localeSource: the string locale, which if not informed, will be considered "en-us".

  • asInteger: boolean value that indicates if the string must be converted to an integer numeric value. In case it is not defined, the default value is false.

Let's say you need to convert two strings referring to a generic numeric value and a monetary value:

{
"generic": "150.33",
"currency": "US$ 300,754.15"
}

Applying the conversion:

{
"generic": {{ TONUMBER(message.generic, "###.##") }},
"currency": {{ TONUMBER(message.currency, "'US$ '###,###.##") }}
}

The result will be:

{
"generic": 150.33,
"currency": 300754.15
}

Other formatting examples::

String Format Numeric

"123.456" ###.# 123.5

"009.95" 000.### 9.95

"0.95" ##0.### 0.95

"-300" '-'### -300

RANDOMNUMBERS

This function allows you to generate random integer numbers based on a range of values.

Syntax

RANDOMNUMBERS(minValue, maxValue)

Let's say you need to generate a random number between 0 and 50000.

Generate the number:

{
"randomNumber": {{ RANDOMNUMBERS(0, 50000) }}
}

The result will be:

{
"randomNumber": 37122
}

The values that define the range are inclusive.

IMPORTANT: the function has a numerical limitation and only accepts values between the range of -9223372036854775808 to 9223372036854775807. Any other value out of those limits will result in an unpredictable execution of the function.

You can also read about these functions:

Did this answer your question?