Round (FPScript)

21.09.2021

Rounds up to a predefined number of valid decimal places or to a multiple of a specified rounding interval.

Syntax

Round(Number, Places)
or
Round(Number, Interval, Rule)

 

The syntax of the Round function consists of the following parts:

Part

Description

Number

The real or complex number that is rounded.

All data structures are allowed. All numeric data types are permitted.

If the argument is a list, then the function is executed for each element of the list and the result is also a list.

Places

Specifies the number of places to which to round.

Permitted data structures are scalar value. All numeric data types are permitted.

The value must be greater or equal to 1.

For complex data types the absolute value is formed.

If the argument is a list, then the first element in the list is taken. If this is also a list, then the process is repeated.

Interval

Specifies the rounding interval.

Permitted data structures are scalar value. All numeric data types are permitted. The unit has to be compatible with that of parameter Number.

The value must be greater than 0.

For complex data types the absolute value is formed.

If the argument is a list, then the first element in the list is taken. If this is also a list, then the process is repeated.

Rule

Specifies which rounding value is to be used as the result in the event that the value to be rounded is exactly in the middle between two neighboring multiples of the rounding interval.

The argument Rule can have the following values:

Constant

Meaning

ROUND_EVEN_UP

The even multiple is used.

ROUND_MID_UP

The greater multiple is used.

If the argument is a list, then the first element in the list is taken. If this is also a list, then the process is repeated.

Remarks

The result has the same structure and unit as the argument Number.

For signals, only the Y component is considered. For complex numbers, the real and imaginary parts are rounded separately.

Available in

FlexPro Basic, Professional, Developer Suite

Examples

Round(1.2345, 2)

Results in 1.200.

Round(1.253 N, 2)

Results in 1.300 N.

Round(12745, 2)

Results in 13000.

Round(-1.234, 2)

Results in -1.200.

Round(12.223, 0.1, ROUND_EVEN_UP)

Results in 12.2.

Round(12.251 N, 0.1, ROUND_EVEN_UP)

Results in 12.3 N.

Round(12.275 N, 100 mN, ROUND_EVEN_UP)

Results in 12.3 N.

Round(1223.3, 10, ROUND_EVEN_UP)

Results in 1220.

Round(1223.3, 10, ROUND_EVEN_UP)

Results in 1220.

Round(-1227.5, 10, ROUND_EVEN_UP)

Results in -1230.

Round(12.25, 0.1, ROUND_EVEN_UP)

Results in 12.2.

Round(12.35, 0.1, ROUND_EVEN_UP)

Results in 12.4.

Round(12.25, 0.1, ROUND_MID_UP)

Results in 12.3.

Round(12.35, 0.1, ROUND_MID_UP)

Results in 12.4.

See Also

RoundUp Function

RoundDown Function

Share article or send as email:

You might be interested in these articles