# Calculate MODULO?

**URL:** <https://discourse.nodered.org/t/calculate-modulo/85052>\
**Category:** General\
**Tags:** function-node\
**Created:** [30 January 2024 19:40 UTC](https://discourse.nodered.org/t/calculate-modulo/85052 "2024-01-30T19:40:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ArmarellaDaisy](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@ArmarellaDaisy](https://discourse.nodered.org/u/ArmarellaDaisy)\
**Post date:** [30 January 2024 19:40 UTC](https://discourse.nodered.org/t/calculate-modulo/85052/1 "2024-01-30T19:40:26Z")

</div>

Hi Guys,

I want to calculate a value in steps of 5.  
17 -\> 20  
12 -\> 15  
24.5 -\> 25  
is this somehow possible using Modulo ?

lG  
Daisy

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [30 January 2024 19:51 UTC](https://discourse.nodered.org/t/calculate-modulo/85052/2 "2024-01-30T19:51:58Z")

</div>

Use `ceil`.

```auto
const x = 17
Math.ceil(x / 5) * 5; /* 20 */

```

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [31 January 2024 05:34 UTC](https://discourse.nodered.org/t/calculate-modulo/85052/3 "2024-01-31T05:34:46Z")

</div>

This should also work, using basic operators only.

```auto
x - x % 5 + 5

```

To floor instead of ceil, just omit the `+ 5`.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [31 January 2024 07:27 UTC](https://discourse.nodered.org/t/calculate-modulo/85052/4 "2024-01-31T07:27:32Z")

</div>

That doesn't seem to achieve the desired result

Never mind, I read what you actually typed now!

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [31 January 2024 07:29 UTC](https://discourse.nodered.org/t/calculate-modulo/85052/5 "2024-01-31T07:29:22Z")

</div>

> [@jbudd](#):
>
> That doesn't seem to achieve the desired result

You missed the first part of the equation.

```auto
12 - 12 % 5 + 5 = 15

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [31 January 2024 07:44 UTC](https://discourse.nodered.org/t/calculate-modulo/85052/6 "2024-01-31T07:44:05Z")

</div>

Am I missing something as it does not work for 5, 10, 15, etc.

15- 15 % 5 + 5 = 20

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [31 January 2024 07:51 UTC](https://discourse.nodered.org/t/calculate-modulo/85052/7 "2024-01-31T07:51:00Z")

</div>

You're right... 🥴

One shouldn't do math before coffee! 🙈 Embarrassing!

I think we should stick with Marcus' solution! 🤣

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [31 January 2024 07:59 UTC](https://discourse.nodered.org/t/calculate-modulo/85052/8 "2024-01-31T07:59:55Z")

</div>

It’s rare I get these things!  
Maths isn’t my strong point, like at all!

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [31 January 2024 09:21 UTC](https://discourse.nodered.org/t/calculate-modulo/85052/9 "2024-01-31T09:21:58Z")

</div>

My thinks whoever comes here looking to **"Calculate MODULO"** is not gonna be happy 😉

Perhaps the title should be updated to "How do I round up a number?"

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [14 February 2024 09:22 UTC](https://discourse.nodered.org/t/calculate-modulo/85052/10 "2024-02-14T09:22:39Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
