Round to decimal places (round_decimals)¶
What it does: Rounds a number to the specified number of decimal places.
Inputs¶
NUM: the number you want to round.- Field
PLACES: number of decimal places from0to6.
Output¶
- rounded number (Number).
When to use it¶
- when you want to shorten the result from an ADC, sensor or other measurement to a readable format.
- when you need to accurately set the number of decimal places before displaying or sending data.
Tips and pitfalls¶
PLACES = 0means rounding to an integer.- Unlike
math_round, it does not solve the direction of rounding, but only the number of decimal places. - When the input cannot be converted to a number, the generated auxiliary block returns the original value unchanged.
Generated Python example¶
def round_decimals(x, n):
try:
return round(float(x), int(n))
except:
try:
return round(x, int(n))
except:
return x
hodnota = round_decimals(12.3456, 2)