Truncate Average Temperature to Two Decimal Places


#1

1) Give a description of the problem
The routine is to assign average temperatures into a variable

2) What is the expected behaviour?
It is doing what it is supposed to do

3) What is happening/not happening?
It is providing an average of up 12 decimal places, I want to limit it to two places

**4) Post a Green Snapshot of the piston![image|45x37]


#2

You can use the round function to limit decimal places…round(number, # of decimal places)

Personal preference, I would set a local variable first, round it, then set the global variable

Set variable AvgTemp1 = Average of Device 1, Device 2…
Set variable AvgTemp1 = round(AvgTemp1, 2)
Set variable @@AvgTemp1 = AvgTemp1


#3

Agreed, the problem I have is it is not allowing me to:

Set variable AvgTemp1 = round(AvgTemp1, 2)

I have tried all Value choices and none put the value of the variable in the argument statement.

Also,

Set variable @@AvgTemp1 = AvgTemp1

Will not allow me to enter AvgTemp1 as the variable to derive value from.

I did define AvgTemp1 as a dynamic variable

What am I missing?


#4

AvgTemp1 should be a decimal variable

Initially set just like before for average of each device temp…

The round function has to go into the expression field


#5

That was the fix, thank you.


#6

Awesome, there are ways to make it look a little cleaner if you are interested.

Something I like to do is create a device list variable so that if you ever want to add or remove devices you just change the one variable; this is a simple use case so probably not a big deal but helpful if you are referring to the same device list multiple times in a piston.


#7

When I was coding for a living I did the same – creating a variable table. Of course, you should always go back and tighten the code

TBH this is the first time I have needed to create a variable in WebCore :slight_smile: