Macro Express Forums

# How to test if a number is a multiple of 5

## Recommended Posts

I want to test whether a number is a multiple of 5. Is there a way to test whether the result of a division is an even number?

I've tried testing whether the last digit is a 0 or a 5 but so far it's not working.

Thanks.

##### Share on other sites

1) Divide your number by 5, save this result (res1)

2) Multiply res1 by 5, save this result (res2)

3) If your number equals res2, your number is divisible by 5

Same with odd/even numbers, using 2 as the divisor.

##### Share on other sites

1) Divide your number by 5, save this result (res1)

2) Multiply res1 by 5, save this result (res2)

3) If your number equals res2, your number is divisible by 5

Same with odd/even numbers, using 2 as the divisor.

This works if you are using Integer variables.

Something like this might work if you want to use Decimal variables:

```Variable Modify Decimal: %D2% = %D1% / 5
Variable Modify Decimal: Copy fraction part of %D2% to %D3%
Variable Modify Decimal: %D4% = %D3% * 5
Round Decimal Variable %D4% to 0 decimal places
If Variable %D4% = 0
// Divisible by 5
Else
// Not divisible by 5
End If```

##### Share on other sites

1) Divide your number by 5, save this result (res1)

2) Multiply res1 by 5, save this result (res2)

3) If your number equals res2, your number is divisible by 5

Same with odd/even numbers, using 2 as the divisor.

I'm afraid this doesn't make sense to me. Isn't dividing by 5 and then multiplying by 5 the same thing as multiplying by 1??

125 / 5 = 5.

5 x 5 = 125.

##### Share on other sites

I'm afraid this doesn't make sense to me. Isn't dividing by 5 and then multiplying by 5 the same thing as multiplying by 1??

125 / 5 = 5.

5 x 5 = 125.

Try these:

124/5 = 24

24*5 = 120

125 <> 120, therefore 124 is not a multiple of 5

125/5 = 25 (not 5 as you wrote above)

25*5 = 125

125 = 125, therefore 125 is a multiple of 5

QED

##### Share on other sites

Meanwhile, I just went about it a different way.

If last digit of variable equals five

Or

If last digit of variable equals zero

Else

----- warn the user that his input variable is not a multiple of five

End If

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.