# Anyway to round down decimal variables in logic calculation?

**URL:** <https://community.homey.app/t/anyway-to-round-down-decimal-variables-in-logic-calculation/78005>\
**Category:** Questions & Help\
**Created:** [March 18, 2023, 10:12pm UTC](https://community.homey.app/t/anyway-to-round-down-decimal-variables-in-logic-calculation/78005 "2023-03-18T22:12:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![BIRDY](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/birdy/32/41476_2.png) [@BIRDY](https://community.homey.app/u/BIRDY)\
**Post date:** [March 18, 2023, 10:12pm UTC](https://community.homey.app/t/anyway-to-round-down-decimal-variables-in-logic-calculation/78005/1 "2023-03-18T22:12:26Z")

</div>

Anyway to round down decimal variables in logic calculation?

---

<div class="post-metadata">

**Author:** ![Caseda](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/caseda/32/138695_2.png) [@Caseda](https://community.homey.app/u/Caseda)\
**Post date:** [March 18, 2023, 10:17pm UTC](https://community.homey.app/t/anyway-to-round-down-decimal-variables-in-logic-calculation/78005/2 "2023-03-18T22:17:21Z")

</div>

round it like normal: `{{ round(NUMBER) }}`  
~~round it up: `{{ roof(NUMBER) }}`~~  
round it up: `{{ ceil(NUMBER) }}`  
round it down: `{{ floor(NUMBER) }}`

---

<div class="post-metadata">

**Author:** ![BIRDY](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/birdy/32/41476_2.png) [@BIRDY](https://community.homey.app/u/BIRDY)\
**Post date:** [March 19, 2023, 4:59pm UTC](https://community.homey.app/t/anyway-to-round-down-decimal-variables-in-logic-calculation/78005/3 "2023-03-19T16:59:08Z")

</div>

Yes I did see this earlier but what i was wondering is that the function rond up you can specify how many decimals you want to round up on. The same method does not work with floor(VALUE,n).

Is this a limitation of the function " floor()"?

---

<div class="post-metadata">

**Author:** ![Caseda](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/caseda/32/138695_2.png) [@Caseda](https://community.homey.app/u/Caseda)\
**Post date:** [March 19, 2023, 5:03pm UTC](https://community.homey.app/t/anyway-to-round-down-decimal-variables-in-logic-calculation/78005/4 "2023-03-19T17:03:57Z")

</div>

this is indeed a limitation of the build in logic’s calculation card, though that is of course very easy to fix with regular calculus:  
1 decimal: `{{ floor(NUMBER * 10) / 10 }}`  
2 decimals: `{{ floor(NUMBER * 100) / 100 }}`  
etc

It might be possible with the “better logic library” app with the `floor(VALUE, n)` way.

---

<div class="post-metadata">

**Author:** ![Patrick\_Van\_Deursen](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/patrick_van_deursen/32/56539_2.png) [@Patrick\_Van\_Deursen](https://community.homey.app/u/Patrick_Van_Deursen)\
**Post date:** [October 10, 2024, 5:55pm UTC](https://community.homey.app/t/anyway-to-round-down-decimal-variables-in-logic-calculation/78005/5 "2024-10-10T17:55:57Z")

</div>

I have tried to execute the Floor command on BLL, but get an error. the code is:

{{floor((Number),0)}}

the error is: ReferenceError: floor is not defined

Any pointers?

---

<div class="post-metadata">

**Author:** ![SunBeech](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sunbeech/32/111391_2.png) [@SunBeech](https://community.homey.app/u/SunBeech)\
**Post date:** [October 10, 2024, 7:05pm UTC](https://community.homey.app/t/anyway-to-round-down-decimal-variables-in-logic-calculation/78005/6 "2024-10-10T19:05:11Z")

</div>

I think the function is `math.floor(number, decimals)`.

Source: [math.js | an extensive math library for JavaScript and Node.js](https://mathjs.org/docs/reference/functions/floor.html)

---

<div class="post-metadata">

**Author:** ![Patrick\_Van\_Deursen](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/patrick_van_deursen/32/56539_2.png) [@Patrick\_Van\_Deursen](https://community.homey.app/u/Patrick_Van_Deursen)\
**Post date:** [October 12, 2024, 10:37am UTC](https://community.homey.app/t/anyway-to-round-down-decimal-variables-in-logic-calculation/78005/7 "2024-10-12T10:37:29Z")

</div>

so the correct usage in BLL is:

{{floor(number)}}. no need for the ,0

---

<div class="post-metadata">

**Author:** ![SunBeech](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sunbeech/32/111391_2.png) [@SunBeech](https://community.homey.app/u/SunBeech)\
**Post date:** [October 12, 2024, 1:58pm UTC](https://community.homey.app/t/anyway-to-round-down-decimal-variables-in-logic-calculation/78005/8 "2024-10-12T13:58:49Z")

</div>

You need to add the **Math.** part.

Also if you use BLL’s calculate card (Voer uit) then you don’t have to use the leading and trailing braces:

 ![Math.floor](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/a/2/a2834da6e6df716c6931eaf897360a2216f2a00b.png)

Based on the earlier referenced documentation I understand that the default behaviour of this function is to round down to no decimals. So you can skip the ‘,0’. Note that if you do provide a decimal argument, the funtion still rounds down to no decimals in my case.

---

<div class="post-metadata">

**Author:** ![Jumpingtrees](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jumpingtrees/32/79538_2.png) [@Jumpingtrees](https://community.homey.app/u/Jumpingtrees)\
**Post date:** [December 27, 2024, 12:50pm UTC](https://community.homey.app/t/anyway-to-round-down-decimal-variables-in-logic-calculation/78005/9 "2024-12-27T12:50:43Z")

</div>

Stumbled across this useful thread, but there is a small error. To round up the correct function is math.ceil.

```auto
math.ceil(x)
math.ceil(x, n)
math.ceil(unit, valuelessUnit)
math.ceil(unit, n, valuelessUnit)

```

[math.js | an extensive math library for JavaScript and Node.js](https://mathjs.org/docs/reference/functions/ceil.html)
