#

# LogiView

## Function 'rnd'

| This function is used to round a numeric value to a defined accuracy.
| ### Syntax:
| {INT_VAR|FLO_VAR}= rnd({NUM_EXPR}) or {INT_VAR|FLO_VAR}= rnd({NUM_EXPR},{1|2|3|4|5|6})
| ### I/O parameters:
| {NUM_EXPR} | Numeric expression to be rounded.
| {1|2|3|4|5|6} | Number of desired digits following the decimal point used for rounding the forwarded value (because the argument is a numeric expression, only the interger portion is accounted).
n (<=6) | Number if digits following the decimal point. Rounding is performed to a float value with a defined accuracy.
| - |
| ### Return value:
| {INT_VAR|FLO_VAR} | Integer or float value containing the result of this function.
| ### Example:
| Declaration of Variables
T | Zei | Cond/Curr | R 01 | R02 | R03 | ELSE
C | 10 | DT rounds the given number from one to three digits | : | : | : |
B | 10 | DOCU_INT_1== | 1 | 2 | 3 |
|  | ------------------------------------------------------------------------ | ------- | ------- | -------- | ---------
A | 10 | put(rnd(23.2641758,1)) | yes | no | no | no
A | 20 | put(rnd(23.2641758,2)) | no | yes | no | no
A | 30 | put(rnd(23.2641758,3)) | no | no | yes | no
A | 40 | put("Please enter a number from 1 to 3!") | no | no | no | yes
| Result:
| In this example the constant 23,2641758 was rounded to three digits behind the decimal point. If another number than the defaulted 1 to 3 digits is entered for the digits behind the decimal point, an error message is displayed.
| In this example, the six-digit display is caused by using the command 'put'. In order to prevent errors, the float/double type must be used if results can be expected to be either very large or very small (<2^-31 or > 2^31).
| Functions and commands: Mathematics