Results 1 to 16 of 16

Thread: Apparently 5.2 MOD 4.6 = 0 but why? [resolved]

  1. #1

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774

    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.
    ?
    'What's this bit for anyway?
    For Jono

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    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

  3. #3

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774
    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.
    ?
    'What's this bit for anyway?
    For Jono

  4. #4

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774
    Originally posted by si_the_geek
    5.2-(4.6*(5.2\4.6)) = 0.600000000000001
    no it doesn't
    ?
    'What's this bit for anyway?
    For Jono

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    no it doesn't
    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:
    1. Function MyMod(NumberA, NumberB)
    2.   MyMod = NumberA-(NumberB*(NumberA\NumberB))  
    3. End Function
    4.  
    5. 'usage:
    6. If MyMod(A,B) = 0 Then ...

    admittedly you'll want to cut off the extra decimal places, but you get the idea

  6. #6

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774
    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.
    ?
    'What's this bit for anyway?
    For Jono

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    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)))

  8. #8
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    Alternatively, you could multiply the values by 10^x, then divide the result by 10^x.

  9. #9

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774
    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...
    ?
    'What's this bit for anyway?
    For Jono

  10. #10
    New Member
    Join Date
    Jan 2004
    Posts
    4

    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

  11. #11
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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

  12. #12
    New Member
    Join Date
    Jan 2004
    Posts
    4
    Thank you!
    No problemo

  13. #13
    Lively Member
    Join Date
    Apr 2003
    Location
    Georgetown, Texas
    Posts
    114
    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!

  14. #14
    New Member
    Join Date
    Jan 2004
    Posts
    4
    Originally posted by RAEsquivelC
    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!
    I sincerely hope so

  15. #15
    Lively Member
    Join Date
    Apr 2003
    Location
    Georgetown, Texas
    Posts
    114
    Well, Access aparently does NOT!

  16. #16
    New Member
    Join Date
    Jan 2004
    Posts
    4
    Very strange indeed...

    5.5 Mod 4.2 yields 0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width