Checking if a Number is Exactly Divisible by Specific Values | Community
Skip to main content
_Manish_Singh
New Participant
June 10, 2023
Solved

Checking if a Number is Exactly Divisible by Specific Values

  • June 10, 2023
  • 3 replies
  • 1769 views

Hello community,


I'm working with Fusion and I'm trying to find a way to determine if a number (input bundle) is exactly divisible by specific values using math functions available. Specifically, I want to check if decimal values (representing hours) are divisible by numbers like 8.1, 8 or 7.5 (see table below)


Is there a built-in function or a combination of functions that can help me achieve this? I'll be using routers, so as a starting point the logic for divisibility by 8 would suffice. Thank you in advance for your support!

Bundles:

entryDatehours
01-02-202332
03-05-202322.5
31-01-202332.4
26-02-202316
12-04-202316.2
01-06-202314

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by William--

Would be nice if Fusion had a function to check if a value is an integer or not, but since it doesn't (to my knowledge), the below can be used. (this matches the logic provided by Doug)

Since you're using a router, I've put this logic in a filter to determine if the bundle should pass the filter or not: 
This uses an IF statement that only allows TRUE responses to pass through:
"if X / Y = a whole number, then X / Y will also = the rounded value of X / Y" E.g.:

10 / 8 = 1.25
The rounded value of 10 / 8 = 1
1.25 does not equal 1, therefore the comparison returns "false." 

24/ 8 = 3
The rounded value of 24 / 8 = 3
3 does equal 3, therefore the comparison returns "true." 

3 replies

ChrisStephens
New Participant
June 12, 2023

Fusion has a MOD function in it, which can indicate divisibility. The format is {{numerator & denominator}}, or for example, this: {{100 % 2}}. It will return 0 for divisibility = true, or 1 for divisibility = false.

 

Edit: This is sort of right, see my follow up comment below.

_Manish_Singh
New Participant
June 12, 2023

Thank you, Chris. However, when I tested the expression "{{100 % 8}}", it returned a remainder of 4.

ChrisStephens
New Participant
June 12, 2023

Oof no yeah, you're right. No late-night posting for me.

The mod command is the modulus command, so it shows the remainder. So for 100 mod 8, 96 (12 * 8 ] is the greatest whole number you can end up with, with a remainder of 4 (100 - 96). So if the result is 0, then that means there was no remainder left, and so the numerator is wholly divisible. (Note: ] is only because if I use normal paren it converts to emoji)

William--
William--Accepted solution
New Participant
June 10, 2023

Would be nice if Fusion had a function to check if a value is an integer or not, but since it doesn't (to my knowledge), the below can be used. (this matches the logic provided by Doug)

Since you're using a router, I've put this logic in a filter to determine if the bundle should pass the filter or not: 
This uses an IF statement that only allows TRUE responses to pass through:
"if X / Y = a whole number, then X / Y will also = the rounded value of X / Y" E.g.:

10 / 8 = 1.25
The rounded value of 10 / 8 = 1
1.25 does not equal 1, therefore the comparison returns "false." 

24/ 8 = 3
The rounded value of 24 / 8 = 3
3 does equal 3, therefore the comparison returns "true." 

If you like my content, please take a moment to view and vote on my Idea Requests: https://tinyurl.com/4rbpr7hf
_Manish_Singh
New Participant
June 10, 2023

@william-- Thank you for the detailed explanation 🙂

Doug_Den_Hoed__AtAppStore
New Participant
June 10, 2023

 

 
There is no native MOD function, but IF(ROUND(hours/8) = hours/8),”8 Exactly”,”Not 8”) etc. is a possible workaround.
 
Regards,
Doug
_Manish_Singh
New Participant
June 10, 2023

Thanks Doug!! 🙂