Division irregularities

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Parul Bagadia
    New Member
    • Mar 2008
    • 188

    Division irregularities

    In my assignment of converting a number from one base system to another, whenever m dividing a decimal no; an integer in dat type by some number; many irregular results are coming; which i got when i debugged my program.
    For converting a no, to binary when m dividing it by 2; only for special cases like; for 7/2 i got 4 instead of 3 and hence the complete answer is changing.
    For 15/16 i got 1 instead of 0.
    A very small part of my one function m posting over here.
    Tell me if u can point out what's wrong,
    Do
    reminder(j) = store Mod 2
    store = store / 2
    j = j + 1
    Loop While (store <> 0)
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    that is because you are using variables of wrong data type . use decimal in place of integer . i hope the problem will be solved.

    Comment

    • vdraceil
      New Member
      • Jul 2007
      • 236

      #3
      Use int() function-it returns only the integer portion of a number.
      Code:
      dim a as integer
      
      a=int(15/16)
      msgbox a
      the output is 0 and not 1.

      Comment

      • Parul Bagadia
        New Member
        • Mar 2008
        • 188

        #4
        Originally posted by debasisdas
        that is because you are using variables of wrong data type . use decimal in place of integer . i hope the problem will be solved.
        I changed my code and used DECIMAL instead of integer; but there is no such data-type itself.

        Comment

        • vdraceil
          New Member
          • Jul 2007
          • 236

          #5
          what about that int() fuction?useful? ?

          Comment

          • Parul Bagadia
            New Member
            • Mar 2008
            • 188

            #6
            Originally posted by vdraceil
            what about that int() fuction?useful? ?
            I dont think so, because instead of 0 m getting 1.....so its not the matter of integer; value itself is coming different..

            Comment

            • Parul Bagadia
              New Member
              • Mar 2008
              • 188

              #7
              Hello ppl, can sbd plz gonna tell me what magic is happening in my program?
              I tried int function which is ofcourse not needed ,also done with decimal as data type in which i got syntax error there itself coz that type doesnt exist; i also wrote another function for division; but invain; m getting illogical answers as 7/2=4 instead of 3.......and so on; the same story..
              Can sbd explain plz?

              Comment

              • xinariscy
                New Member
                • Sep 2008
                • 14

                #8
                Possible solution:

                1) Try to use "\" in the devision instead "/" (YES it's different)

                Comment

                • Parul Bagadia
                  New Member
                  • Mar 2008
                  • 188

                  #9
                  Originally posted by xinariscy
                  Possible solution:

                  1) Try to use "\" in the devision instead "/" (YES it's different)
                  Yaeh it worked!
                  Thank you so much; m done with my complete assignment because of this suggestion.
                  But can u tell me how it worked?
                  I mean i didnt even know that this sign is used for division!...fro m which book or website or from where u got this?
                  Plz tell me; even i want to read.

                  Comment

                  • xinariscy
                    New Member
                    • Sep 2008
                    • 14

                    #10
                    n/p, I just google it because it was really strange:) here it is:



                    See "Table 2"

                    Comment

                    Working...