MOD Operation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark

    MOD Operation

    Why does MsgBox 4.25 MOD 1 display 0? I was hoping to get .25.

    Thanks!

    Mark


  • '69 Camaro

    #2
    Re: MOD Operation

    Hi, Mark.

    Modulus division only returns whole numbers, not fractions.

    HTH.

    Gunny

    See http://www.QBuilt.com for all your database needs.
    See http://www.Access.QBuilt.com for Microsoft Access tips.


    "Mark" <mmorrow@earthl ink.net> wrote in message
    news:7QBRc.1730 4$Jp6.16451@new sread3.news.atl .earthlink.net. ..[color=blue]
    > Why does MsgBox 4.25 MOD 1 display 0? I was hoping to get .25.
    >
    > Thanks!
    >
    > Mark
    >
    >[/color]


    Comment

    • Larry  Linson

      #3
      Re: MOD Operation

      "Mark" wrote
      [color=blue]
      > Why does MsgBox 4.25 MOD 1
      > display 0? I was hoping to get .25.[/color]

      When you round 4.25 to an integer, you get 4. When you divide 4 by 1 you get
      a result of 4 and a remainder of 0. That's why you get 0.

      From Access 2003 (Visual Basic 6.3) Help (and the definition of Mod hasn't
      changed since Access 1.0, AFAIK):

      "Remarks
      The modulus, or remainder, operator divides number1 by number2 (rounding
      floating-point numbers to integers) and returns only the remainder as
      result. For example, in the following expression, A (result) equals 5.
      A = 19 Mod 6.7"


      Comment

      • Larry  Linson

        #4
        Re: MOD Operation

        If you want to show the "fractional part", you could try

        4.25 - Int(4.25)

        Larry Linson
        Microsoft Access MVP

        "Mark" <mmorrow@earthl ink.net> wrote in message
        news:7QBRc.1730 4$Jp6.16451@new sread3.news.atl .earthlink.net. ..[color=blue]
        > Why does MsgBox 4.25 MOD 1 display 0? I was hoping to get .25.
        >
        > Thanks!
        >
        > Mark
        >
        >[/color]


        Comment

        • Don Leverton

          #5
          Re: MOD Operation

          Hi Mark,

          After having read all of these replies, I thought "OK .. try this..."

          Dim MyValue as Long
          MyValue = 4.25

          Dim MyNumber As Long
          MyNumber = (MyValue * 100)

          Dim MyRemainder as Long
          MyRemainder = (MyNumber MOD 100) / 100

          --
          HTH,
          Don
          =============== ==============
          E-Mail (if you must) My.Name@Telus.n et

          Disclaimer:
          Professional PartsPerson
          Amateur Database Programmer {:o)

          I'm an Access97 user, so all posted code samples are also Access97- based
          unless otherwise noted.

          =============== =============== =============== =============== =============== =
          ====
          I was "anally raped" on a Timeshare deal by Club All Seasons

          , Les Volieres du Quebec, and Club Privilege.

          In appreciation for that, please feel free to forward SPAM and VIRUSES to:
          chantallemay@be llnet.ca
          ipiquet@hotmail .com
          info@volieres.c om

          Don't get mad --- get even! :-)
          =============== =============== =============== =============== =============== =
          ====




          "Mark" <mmorrow@earthl ink.net> wrote in message
          news:7QBRc.1730 4$Jp6.16451@new sread3.news.atl .earthlink.net. ..[color=blue]
          > Why does MsgBox 4.25 MOD 1 display 0? I was hoping to get .25.
          >
          > Thanks!
          >
          > Mark
          >
          >[/color]


          Comment

          Working...