Issue with MOD-formula

zweiunddreissig

New Member
Joined
Jun 17, 2021
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
Dear community,

I need your expert advice!

I am working on a sheet to calculate fees.

For the amount field, I have used the following formula in "Data Validation": =MOD(E23*100;2)=0
-> The rule should avoid users to enter more than two decimal places.

Now I have noticed that odd decimal places get an error message, however, even decimal places are ok.

Examples:
100.12 -> ok
100.13 ->nok

What is wrong with my formula? The cell should allow even and odd decimal places as long there are not more than 2 decimal places.

Many thanks for your help!!!

Best regards,
B.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Welcome to the Board!

Your MOD formula does NOT check the number of decimal places.
What it does is check the remainder of division when you mulitply the value by 100 and then divide that by 2.

So, if you have 100.13, then multiplying 100 will give you 10013.
If you divide that by 2, you get 5006, with a remainder of 1. So the MOD formula would return 1, not 0 for that example.

If you want to limit to two decimals, try this formula instead:
Excel Formula:
=(E23*100)-INT(E23*100)=0
 
Upvote 0
To use the MOD function you should 1 not 2 like
Excel Formula:
=MOD(E23*100,1)=0
 
Upvote 0
To use the MOD function you should 1 not 2 like
Excel Formula:
=MOD(E23*100,1)=0
Well, that certainly is easier.
Don't know why I never considered just dividing by 1 in the MOD formula!
o_O

I guess that is a sign for me to log off and get away from the comptuer for a while!
 
Upvote 0
Welcome to the Board!

Your MOD formula does NOT check the number of decimal places.
What it does is check the remainder of division when you mulitply the value by 100 and then divide that by 2.

So, if you have 100.13, then multiplying 100 will give you 10013.
If you divide that by 2, you get 5006, with a remainder of 1. So the MOD formula would return 1, not 0 for that example.

If you want to limit to two decimals, try this formula instead:
Excel Formula:
=(E23*100)-INT(E23*100)=0

Thank you so much for your help!!!!
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
Don't know why I never considered just dividing by 1 in the MOD formula!
o_O
Probably because it is not a "natural" thing to do. Using 1 as the modulus to return the fractional part of a floating point number in a modulo calculation is strictly an Excel worksheet formula implementation. The mathematical definition of MOD works only with whole numbers. VBA follows that rule with its Mod operator deliberately rounding any floating point numbers to integer values (using Bankers Rounding) before performing the modulo operation. While Excel's formula implementation of the MOD function is useful, it is not "standard" in any way.
 
Upvote 0
It is very possible I'm mistaken, but wouldn't
Excel Formula:
=MOD(E23*100,1)=0
have the problem with the way Excel handles floating point such that some results would not be zero (0.07 or 144.73)

Would this be a safer route?
Excel Formula:
=MID(TEXT(E23,"0000000.0000000"),11,5)="00000"
 
Upvote 0
Probably because it is not a "natural" thing to do. Using 1 as the modulus to return the fractional part of a floating point number in a modulo calculation is strictly an Excel worksheet formula implementation. The mathematical definition of MOD works only with whole numbers. VBA follows that rule with its Mod operator deliberately rounding any floating point numbers to integer values (using Bankers Rounding) before performing the modulo operation. While Excel's formula implementation of the MOD function is useful, it is not "standard" in any way.
I like that explanation. After all, I was a Math major in college, not Computer Science. So maybe my brain naturally went there.
(That's my story and I am sticking with it!) ;)
 
Upvote 0

Forum statistics

Threads
1,223,703
Messages
6,173,973
Members
452,540
Latest member
haasro02

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top