Hello,
We have the following use case:
- In Recipe we have a parameter that is calculated based on other parameters (example image below).
- However, the result should come rounded to a few decimal (IoT restrictions).
Is there a manner to round the values on the Expression field?
Note*: The Parameter definition “Format” only works for the GUI definition and not the calculated value. The IoT layer still receives the full value.
Thanks. Regards,
Elder Hernandez
Hi Elder,
From what I know this expression is not JSONata, it’s using our Expression Evaluator and from what I see in the documentation there is no round function available (Expression Evaluator - Critical Manufacturing Documentation Portal).
The workaround I see is instead of an Expression to use a Rule.
Hope someone else has a better solution 
Ricardo
If it absolutely has to be the expression evaluator, you are somewhat limited with the given set of function you have.
You can try to round round with a function like this:

For positive values of x you can approximate the floor function like this:

And then you can use something like this:
(x * exp(n * log(10)) + 0.5 - ((x * exp(n * log(10)) + 0.5) % 1) ) / exp(n * log(10))
where x is your variable and n the number of places to round to.
BUT, and that is a big BUT - since we are using floating point arethmetic, it’s impossible to correctly represent a lot of decimal expressions.
If the IoT implementation is able to parse strings back to numbers you could try something like this to strip the decimal places when the parameter with the expression defined is string:
(
token(x & “”, “.”, 0)
&
if(
n > 0 && contains(x & “”, “.”),
“.” & substring(
token(x & “”, “.”, 1),
0,
length(token(x & “”, “.”, 1))
- (length(token(x & “”, “.”, 1)) - n)
),
“”
)
) * 1
Hi @Elder_Hernandez, try this as a workaround (2 decimal cases):
(($Oven_Temperature_1+$Oven_Temperature_2+$Oven_Temperature_3+$Oven_Temperature_4)/4+0.005)-(($Oven_Temperature_1+$Oven_Temperature_2+$Oven_Temperature_3+$Oven_Temperature_4)/4+0.005)%0.01