|
-
Jan 22nd, 2004, 08:20 AM
#1
Thread Starter
Fanatic Member
Apparently 5.2 MOD 4.6 = 0 but why? [resolved]
can anyone tell me why 5.2 MOD 4.6 = 0 is returned by access accross some 55 PCs all over the UK?
Last edited by Matt_T_hat; Jan 22nd, 2004 at 10:51 AM.
-
Jan 22nd, 2004, 08:36 AM
#2
Mod is for Integer arithmetic.. it doesnt work with floating point numbers 
an aternative method is:
5.2-(4.6*(5.2\4.6)) = 0.600000000000001
-
Jan 22nd, 2004, 09:05 AM
#3
Thread Starter
Fanatic Member
Originally posted by si_the_geek
an aternative method is:
5.2-(4.6*(5.2\4.6)) = 0.600000000000001
So if I understand correctly
Hmm...
I would code something...
I understand the reason for the MOD not working now
How does... never mind
Last edited by Matt_T_hat; Jan 22nd, 2004 at 09:52 AM.
-
Jan 22nd, 2004, 09:14 AM
#4
Thread Starter
Fanatic Member
Originally posted by si_the_geek
5.2-(4.6*(5.2\4.6)) = 0.600000000000001
no it doesn't
-
Jan 22nd, 2004, 09:52 AM
#5
yes it does... notice \ rather than /
( \ returns an integer only, which is what we want )
so:
5.2-(4.6*(5.2\4.6))
=> 5.2-(4.6*(1))
=> 5.2-(4.6)
=> 0.6 (usual floating point problem gives the extra dp's)
How does your alternative work if the numbers A and B are unknown and you want to find if A is and exact multiple of B?
if you mean the equivalent of:
If (A MOD B = 0) Then ...
that is:
If (A-(B*(A\B)) = 0) Then ...
this Mod in a function:
VB Code:
Function MyMod(NumberA, NumberB)
MyMod = NumberA-(NumberB*(NumberA\NumberB))
End Function
'usage:
If MyMod(A,B) = 0 Then ...
admittedly you'll want to cut off the extra decimal places, but you get the idea
-
Jan 22nd, 2004, 09:54 AM
#6
Thread Starter
Fanatic Member
Originally posted by si_the_geek
admittedly you'll want to cut off the extra decimal places, but you get the idea
I do indeed get the idea... I was not aware / and \ functioned differently in VB in fact I was unaware of '\' as a math function.
One last Q if I may "...cut off the extra decimal places..." ?
not that it matters... thankyou I tried you code snippit and wow - like a dream! Man that's cool.
You rock.
Last edited by Matt_T_hat; Jan 22nd, 2004 at 10:13 AM.
-
Jan 22nd, 2004, 10:03 AM
#7
One last Q if I may "...cut off the extra decimal places..." ?
that returns 0.600000000000001 rather than 0.6 as it theoretically should (due to the problems of storing floating point numbers on a binary machine).
I think you need to use Val or Format to get it right...
just found this thread: http://www.vbforums.com/showthread.p...hreadid=193491
and it seems CSng() works!
so you should use:
MyMod = CSng(NumberA-(NumberB*(NumberA\NumberB)))
-
Jan 23rd, 2004, 01:34 PM
#8
So Unbanned
Alternatively, you could multiply the values by 10^x, then divide the result by 10^x.
-
Jan 26th, 2004, 04:13 AM
#9
Thread Starter
Fanatic Member
Originally posted by DiGiTaIErRoR
Alternatively, you could multiply the values by 10^x, then divide the result by 10^x.
Yes I understand there is a general Access bug where by you should do n=(n/100)*100 (I am told) the good news is that si_the_geek's method did the job but now we have DiGiTaIErRoR's as well it seems like there truely is more than one way to skin a cat...
-
Jan 28th, 2004, 11:28 AM
#10
New Member
Re: Apparently 5.2 MOD 4.6 = 0 but why? [resolved]
Originally posted by Matt_T_hat
can anyone tell me why 5.2 MOD 4.6 = 0 is returned by access accross some 55 PCs all over the UK?
I wipped out my thrustworthy windows calculator
5.2 mod 4.6 = 0.6
What is mod?
It is the remainder of // after division:
8 mod 4 yields 0 because 2 * 4 = 8 remain = 0
8.2 mod 4 yields 0.2 because 2 * 4 = 8 remain = 0.2
-
Jan 28th, 2004, 12:36 PM
#11
Re: Re: Apparently 5.2 MOD 4.6 = 0 but why? [resolved]
Originally posted by evolver
What is mod?
It is the remainder of // after division
yep
-
Jan 28th, 2004, 01:19 PM
#12
New Member
Thank you!
No problemo
-
Jul 27th, 2004, 04:06 PM
#13
Lively Member
And, calling up Excel, and
entering 5.2 in A1, and
entering 4.6 in B1, and using the equation
=MOD(A1,B1) in C1, I get 0.6 in C1. So, Excel DOES know how to work out this kind of arithmatic!
-
Jul 27th, 2004, 04:37 PM
#14
New Member
-
Jul 27th, 2004, 04:39 PM
#15
Lively Member
Well, Access aparently does NOT!
-
Jul 28th, 2004, 12:29 AM
#16
New Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|