Mod Q

Hap

Well-known Member
Joined
Jul 20, 2005
Messages
647
I would like to use a function like the "Mod" operator. My problem with the Mod operator is that it rounds floating point numbers to integer before returning a value. I am hoping there is another function that I can use that will return the remainder of the division of two floating point numbers.

Any guidance would be appreciated.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,367
Office Version
  1. 365
Platform
  1. Windows
Could you give an example please?

There shouldn't really be a remainder when you divide 2 floating point numbers.

eg

1.2/0.5=2.4

What would you say the remainder was there?

Do you mean the decimal part?
 
Upvote 0

Oaktree

MrExcel MVP
Joined
Jun 20, 2002
Messages
8,115
Office Version
  1. 365
Can you give an example of where the MOD function doesn't return what you'd like?
 
Upvote 0

Hap

Well-known Member
Joined
Jul 20, 2005
Messages
647
The mod function returns the remainder of the division of two integers. If you equate a result to Integer Mod 1 the result is 0 because the all integers are divisible by one but if you equate a result to 19 Mod 2 you will get a result of 1.

I would like to be able to equate 3.14159 Mod 3 and get .14159 or 3.14159 Mod .1 and get .04159.

Hopefully that is a little clearer than mud!

Thanks
 
Upvote 0

Aladin Akyurek

MrExcel MVP
Joined
Feb 14, 2002
Messages
85,210
ADVERTISEMENT
Hap said:
The mod function returns the remainder of the division of two integers. If you equate a result to Integer Mod 1 the result is 0 because the all integers are divisible by one but if you equate a result to 19 Mod 2 you will get a result of 1.

I would like to be able to equate 3.14159 Mod 3 and get .14159 or 3.14159 Mod .1 and get .04159.

Hopefully that is a little clearer than mud!

Thanks

Still mud I guess...

Maybe you're looking for:

=A2-TRUNC(A2)
 
Upvote 0

Hap

Well-known Member
Joined
Jul 20, 2005
Messages
647
That is the right idea. I am trying to code it.

Example

If 1.2345 / .25 = 4.938

Then .25 goes into 1.2345 only 4 times so the remainder
will be .938 * .25

I hope the puddle is getting clearer.
 
Upvote 0

Aladin Akyurek

MrExcel MVP
Joined
Feb 14, 2002
Messages
85,210
ADVERTISEMENT
Hap said:
That is the right idea. I am trying to code it.

Example

If 1.2345 / .25 = 4.938

Then .25 goes into 1.2345 only 4 times so the remainder
will be .938 * .25

I hope the puddle is getting clearer.

What is the desired result: 0.938 or 0.938*0.25?
 
Upvote 0

Hap

Well-known Member
Joined
Jul 20, 2005
Messages
647
I just finished my own Mod Function to do what I want. Maybe there is already something like this out there.



Public Function Mod2(X As Double, Y As Double)

Dim Z As Double
Dim Z2 As Double

Z = X / Y
Z2 = WorksheetFunction.Floor(Z, 1)
Z = Z - Z2
Z = Z * Y

Mod2 = Z

End Function
 
Upvote 0

Forum statistics

Threads
1,195,849
Messages
6,011,954
Members
441,657
Latest member
Diupsy

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
Top