Calculations

Calculations are Value Expressions.

To perform calculations with your Bot, use the syntax {MATH[<Operand 1><Operator><Operand 2>...<Operator><Operand n>]}.

Supported languages

MATH uses English Expressions.

Supported operands

You can use the following operands:

  • numerical values

  • scientific notations

Supported operators

RPA Studio processes operators according to the PEMDAS rule. It supports the following operators:

Operator

Description

+, -, *, /

basic arithmetic operations

%

Modulo operation

==

equals

!=

does not equal

&&

AND operation for two items

||

OR operation for two items

<

less than

>

greater than

<=

less or equal

>=

greater than or equal to

&, |, ^, <<, >>

Bit-wise operators: and, or, xor, left shift, right shift

!, ~

Unary operators: not, bit-wise not

The following examples show how RPA Studio processes operators:

The syntax {MATH[2x2+5]} returns the result 9. It first calculates 2 x 2 and then adds 5.

The syntax {MATH[2x(2+5)]} returns the result 14. It first calculates 2 + 5 and then multiplies the result by 2.

Define number formats

By default, RPA Studio creates numbers in the format defined in the Tosca settings at Project > Settings > TBox > Number Formats.

If the machine on which you create your Bots uses a different format than your application, you need to change the RPA Studio format in one of the ways described in "Define date and number formats".

Combine MATH with other Expressions

You can combine MATH with the following dynamic Expressions:

This example shows how to combine MATH with a Buffer called ExampleBuffer. This Buffer contains the value 1000.

The syntax below returns 2000 as a result of the calculation Buffer value + 1000.

{MATH[{B[ExampleBuffer]}+1000]}

This example shows how to calculate with operands that use different number formats.

You have a Buffer called SampleBuffer with the value 1,000.50. Now you want to add 1000 to the value of this Buffer.

In this case, you first need to convert the format of the Buffer value to the format of the second operand. To do so, use the Module Convert Decimal from the RPA subset.

Convert the format of the Buffer value

Then you can perform your calculation:

Example: Calculate operands with different formats

Use mathematical functions

You can use the following mathematical functions:

Function

Description

Example

Result

Abs

Returns the absolute value of a specified number.

Abs(-1)

1

Ceiling

Returns the smallest integer greater than or equal to the specified number.

Ceiling(1.5)

2

Floor

Returns the largest integer less than or equal to the specified number.

Floor(1.5)

1

Max

Returns the larger of two specified numbers.

Max(1, 2)

2

Min

Returns the smaller of two numbers.

Min(1, 2)

1

Pow

Returns a specified number raised to the specified power.

Pow(3, 2)

9

Round

Rounds a value to the nearest integer or specified number of decimal places.

Round(3.222, 2)

3.22

Sign

Returns a value indicating the sign of a number, i.e. negative values = -1, 0 = 0, positive values = 1

Sign(-10)

-1

Sqrt

Returns the square root of a specified number.

Sqrt(4)

2

Truncate Truncates the decimal places of a value.

Truncate(1.7)

1

This example shows how to combine MATH with the function Round:

The syntax {MATH[Round(2.15,1)]} returns 2.2.

Was this information helpful?

Tricentis RPA Studio Manual 2020.2 © Tricentis GmbH