# Calculation of variables (Logic or better Logic)

**URL:** <https://community.homey.app/t/calculation-of-variables-logic-or-better-logic/39913>\
**Category:** Questions & Help\
**Tags:** flow\
**Created:** [December 27, 2020, 5:07pm UTC](https://community.homey.app/t/calculation-of-variables-logic-or-better-logic/39913 "2020-12-27T17:07:28Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Menne\_Talsma](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/menne_talsma/32/8752_2.png) [@Menne\_Talsma](https://community.homey.app/u/Menne_Talsma)\
**Post date:** [December 27, 2020, 5:07pm UTC](https://community.homey.app/t/calculation-of-variables-logic-or-better-logic/39913/1 "2020-12-27T17:07:28Z")

</div>

Anyone an idea how to perform some advanced calculations fot variables?

I would like to round the number at max 2 decimals

i’ve done some trial-and-errorring with Logic and better logic

Round(,2)  
$round(\<number, 2)  
math.round(, 2)  
{{$math.round(, 2)}}

thus far no succes  
anyone?

---

<div class="post-metadata">

**Author:** ![Rocodamelshekima](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rocodamelshekima/32/8209_2.png) [@Rocodamelshekima](https://community.homey.app/u/Rocodamelshekima)\
**Post date:** [December 27, 2020, 5:12pm UTC](https://community.homey.app/t/calculation-of-variables-logic-or-better-logic/39913/2 "2020-12-27T17:12:27Z")

</div>

{{round (Tag inserted here,2)}}

---

<div class="post-metadata">

**Author:** ![Menne\_Talsma](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/menne_talsma/32/8752_2.png) [@Menne\_Talsma](https://community.homey.app/u/Menne_Talsma)\
**Post date:** [December 28, 2020, 10:16pm UTC](https://community.homey.app/t/calculation-of-variables-logic-or-better-logic/39913/4 "2020-12-28T22:16:29Z")

</div>

WORKS!!  
Now the volume of the Top2000 on all the Sonos in the house increases or decreases nicely proportional

anywhere I can find a tutorial for these kind of syntaxes?  
I’ve searched the community and Google but I get Lost

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [February 19, 2021, 1:57am UTC](https://community.homey.app/t/calculation-of-variables-logic-or-better-logic/39913/5 "2021-02-19T01:57:32Z")

</div>

Same here. I searched my ass off, but very little examples…  
I’m looking for creating an array of names.  
Like {{random(round(1,10))}} results in a number between 1 and 10.  
How about a random pick between John, Ben, Julie, Jill?

---

<div class="post-metadata">

**Author:** ![Edgar](https://avatars.discourse-cdn.com/v4/letter/e/b487fb/32.png) [@Edgar](https://community.homey.app/u/Edgar)\
**Post date:** [May 20, 2021, 8:10am UTC](https://community.homey.app/t/calculation-of-variables-logic-or-better-logic/39913/6 "2021-05-20T08:10:38Z")

</div>

that doesn’t work anymore since last update:

- [Logic] Changes rounding Logic variables from 0 to 2 decimals

very nice the change, but unbelievable that they won’t tell how it works now…  
So, do u have an idea? i want round values with 1 decimal.

---

<div class="post-metadata">

**Author:** ![Menne\_Talsma](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/menne_talsma/32/8752_2.png) [@Menne\_Talsma](https://community.homey.app/u/Menne_Talsma)\
**Post date:** [May 20, 2021, 8:50am UTC](https://community.homey.app/t/calculation-of-variables-logic-or-better-logic/39913/7 "2021-05-20T08:50:47Z")

</div>

Ah, So that’s why this morning Sonos went from soft to Deaffening-loud within one click 😮  
now my ears hurt

---

<div class="post-metadata">

**Author:** ![JPe4619](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jpe4619/32/9017_2.png) [@JPe4619](https://community.homey.app/u/JPe4619)\
**Post date:** [May 20, 2021, 11:21am UTC](https://community.homey.app/t/calculation-of-variables-logic-or-better-logic/39913/8 "2021-05-20T11:21:51Z")

</div>

> [@Edgar](#):
>
> want round values with 1 decimal.

{{round(value\*10)/10 }}

---

<div class="post-metadata">

**Author:** ![Edgar](https://avatars.discourse-cdn.com/v4/letter/e/b487fb/32.png) [@Edgar](https://community.homey.app/u/Edgar)\
**Post date:** [May 20, 2021, 12:51pm UTC](https://community.homey.app/t/calculation-of-variables-logic-or-better-logic/39913/9 "2021-05-20T12:51:07Z")

</div>

Thnx! that works… but what is the new solution, any idea of that?  
why did they changed it? it was the correct way and now a workarround. ☹

---

<div class="post-metadata">

**Author:** ![Edgar](https://avatars.discourse-cdn.com/v4/letter/e/b487fb/32.png) [@Edgar](https://community.homey.app/u/Edgar)\
**Post date:** [May 20, 2021, 12:53pm UTC](https://community.homey.app/t/calculation-of-variables-logic-or-better-logic/39913/10 "2021-05-20T12:53:13Z")

</div>

o dear… i had that also in the beginning. my neighbours now hate me while it never happend again. that is because i limited the max volume in de sonos settings to max 50%

---

<div class="post-metadata">

**Author:** ![Wout\_van\_den\_Dool](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/wout_van_den_dool/32/391_2.png) [@Wout\_van\_den\_Dool](https://community.homey.app/u/Wout_van_den_Dool)\
**Post date:** [May 25, 2021, 5:19am UTC](https://community.homey.app/t/calculation-of-variables-logic-or-better-logic/39913/11 "2021-05-25T05:19:36Z")

</div>

![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/c/e/cefbfbe7b184178a463c195cb2cc7929534c7b6e.png)

What is going wrong and right here?

The watermeter is writing its data in 486.555 Dutch. Where 555 are the liters…… thats why divided by 1000.

Round by 3 numbers behind the comma

---

<div class="post-metadata">

**Author:** ![Rocodamelshekima](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rocodamelshekima/32/8209_2.png) [@Rocodamelshekima](https://community.homey.app/u/Rocodamelshekima)\
**Post date:** [May 25, 2021, 6:12am UTC](https://community.homey.app/t/calculation-of-variables-logic-or-better-logic/39913/12 "2021-05-25T06:12:04Z")

</div>

![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/9/9/993b22ddca778678a6640b8ce2c8027c4fd66b6f.jpeg)  
Divided by 1000??

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [May 25, 2021, 7:51am UTC](https://community.homey.app/t/calculation-of-variables-logic-or-better-logic/39913/13 "2021-05-25T07:51:16Z")

</div>

But… why would you want to round liters to 3 decimals. Liters is the smallest unit in case of a watermeter  
So, the calculation needed looks like this: `{{[tag_eind]-[tag_begin]}}`  
Example: `486.755−486.555=0.2`  
When you want the number `0.2`(m³) in liter units, then all you have to do is multiply it with 1000: `{{([tag_eind]-[tag_begin])*1000}}`  
Example: `(486.755−486.555)*1000=200`

---

<div class="post-metadata">

**Author:** ![DirkG](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/dirkg/32/118897_2.png) [@DirkG](https://community.homey.app/u/DirkG)\
**Post date:** [May 25, 2021, 8:20am UTC](https://community.homey.app/t/calculation-of-variables-logic-or-better-logic/39913/14 "2021-05-25T08:20:06Z")

</div>

For people like me who can’t speak Dutch please translate it in English. Thx!

---

<div class="post-metadata">

**Author:** ![Wout\_van\_den\_Dool](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/wout_van_den_dool/32/391_2.png) [@Wout\_van\_den\_Dool](https://community.homey.app/u/Wout_van_den_Dool)\
**Post date:** [May 25, 2021, 9:21am UTC](https://community.homey.app/t/calculation-of-variables-logic-or-better-logic/39913/15 "2021-05-25T09:21:18Z")

</div>

Ha Peter, dankjewel…. En inderdaad, die drie komma’s zijn onzin…

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [May 25, 2021, 10:16am UTC](https://community.homey.app/t/calculation-of-variables-logic-or-better-logic/39913/16 "2021-05-25T10:16:21Z")

</div>

Whoops Dirk, I Englified my post 😉  
Sometimes I’m writing in English in Dutch topics… I think it comes with age 🤣

---

<div class="post-metadata">

**Author:** ![Kai\_Engvik](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/kai_engvik/32/48687_2.png) [@Kai\_Engvik](https://community.homey.app/u/Kai_Engvik)\
**Post date:** [June 26, 2022, 5:08pm UTC](https://community.homey.app/t/calculation-of-variables-logic-or-better-logic/39913/17 "2022-06-26T17:08:46Z")

</div>

Works for me as of june 22 🙂

---

<div class="post-metadata">

**Author:** ![Edgar](https://avatars.discourse-cdn.com/v4/letter/e/b487fb/32.png) [@Edgar](https://community.homey.app/u/Edgar)\
**Post date:** [June 26, 2022, 8:56pm UTC](https://community.homey.app/t/calculation-of-variables-logic-or-better-logic/39913/18 "2022-06-26T20:56:24Z")

</div>

can u show?

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [June 27, 2022, 12:57pm UTC](https://community.homey.app/t/calculation-of-variables-logic-or-better-logic/39913/21 "2022-06-27T12:57:50Z")

</div>

This is a way to round values to 0.1 or 0.5 or 0.01 or 0.25

Input value:

 ![Screenshot_20220627-144857_Homey](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/0/9/091b32c66910e076f5d64cebfd956ea1309d2ae5.jpeg)

Flow:

 ![Screenshot_20220627-145246_Chrome](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/2/e/2e27f09e41c2a260e7e11fc1f3e8fbbc1bfd7fc9.jpeg)

Output:

 ![Screenshot_20220627-144838_Homey](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/1/2/12ad4401d5a44e0efbb5f661f6c8ac28537d040e.jpeg)

---

<div class="post-metadata">

**Author:** ![JPe4619](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jpe4619/32/9017_2.png) [@JPe4619](https://community.homey.app/u/JPe4619)\
**Post date:** [June 27, 2022, 12:58pm UTC](https://community.homey.app/t/calculation-of-variables-logic-or-better-logic/39913/22 "2022-06-27T12:58:50Z")

</div>

> [@JPe4619](#):
>
> {{round(value\*10)/10 }}

For 2 decimals, use: {{round(value\*100)/100}}

---

<div class="post-metadata">

**Author:** ![Peter\_Bittner](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_bittner/32/16698_2.png) [@Peter\_Bittner](https://community.homey.app/u/Peter_Bittner)\
**Post date:** [July 8, 2023, 4:57am UTC](https://community.homey.app/t/calculation-of-variables-logic-or-better-logic/39913/23 "2023-07-08T04:57:39Z")

</div>

I am trying to work out how to use better logic variables versus logic variables. It looks like Better Logic variables are seperate.  
I want to set a variable to the result of subtracting one Tag from another Tag. I can do this with Better Logic but then I can’t work out how to access the Better Logic variable from other flow cards.

[Next page](https://community.homey.app/t/calculation-of-variables-logic-or-better-logic/39913.md?page=2)
