• # How to cut, round, trim Variables to x.xx format

Hello,
is there a way to use variables, which have this format xx.xx.
So I calc two values and get a value back which is xx.xxxxxxxx
So how could it cut, trim, round ect. convert it into xx.xx format.

Thanks

• @free118 you can use the function `round(value, decimal)` with `value` as the value you want converted and `decimal` the number of digits you want to keep.

I think you can include a calculation. Given `value := a/b` it should be possible to use `result := round((a/b), 2)`.

• great thanks,
but where did I need to do that? In the Config? Rules? …

• @free118 depends where you need it. I use the functions mainly inside rules, but also to smoothen the output in VariablesDevices.

What do you want to do with the value?

• I think in rules would be great.
I would to mail it.
So right now I’ve this:
\$avgTemp = \$sumOfTemp / \$TempAvgCounter

and another rule with
subject:" Status" text:" temperatur 24h: \$avgTemp°C,\n Aktuelle Temperatur: \$Temperatur 1.temperature°C "

so i tried
round(\$avgTemp,2) = \$sumOfTemp / \$TempAvgCounter but this not allowed.
Did I need to do this i a seprate rule?
like
\$avgTemp = round(\$avgTemp,2)?
Thanks

• @free118 sorry, if I confused you. I meant to use it like `\$avgTemp := round((\$sumOfTemp / \$TempAvgCounter), 2)`. Does that work?

edit: I think you can even skip the part to calculate your average in a seperate variable and extra rule if you just need it to send an email. So you put `round((\$sumOfTemp / \$TempAvgCounter), 2)` instead of `\$avgTemp` in your second rule.

• awesome thanks.
this first one works. The second one not.
But it fix the problem
thanks again
great…

• @free118 Thanks for the feedback. A pity the second one doesn’t work, maybe with some curly braces around it? `{round((\$sumOfTemp / \$TempAvgCounter), 2)}`. I havent quite figured out how to put strings together yet.

• year that’s it

Posts 9Views 3993

Looks like your connection to pimatic forum was lost, please wait while we try to reconnect.