# Mod Q

#### Hap

##### Well-known Member
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.

#### Norie

##### Well-known Member
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?

#### Oaktree

##### MrExcel MVP
Can you give an example of where the MOD function doesn't return what you'd like?

#### Hap

##### Well-known Member
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

##### MrExcel MVP
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)

#### Hap

##### Well-known Member
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.

##### MrExcel MVP
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?

.938*.25

#### Hap

##### Well-known Member
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

#### Scott Huish

##### MrExcel MVP
=((A1/B1)-INT(A1/B1))*B1