Results 1 to 8 of 8

Thread: something funny

  1. #1

    Thread Starter
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Angry something funny

    VB Code:
    1. Dim S as Single
    2. Dim S1 as Integer
    3. S = 5.2
    4. S1 = Int(s)
    5. Msgbox S - S1

    Something is wrong in my PC or my Math teacher has lied, but i think 5.2 - 5 is 0.2, not 0.199998....
    Is this a problem in VB or my Celeron is sucks?

    (with Double this problem solved but its..... tricky)

    answer please... (urgent)

  2. #2
    Hyperactive Member Gtarawneh's Avatar
    Join Date
    Mar 2002
    Location
    Unknown
    Posts
    382

    WeIrD

    What the hell?
    The same thing is happening here,,,,

  3. #3

    Thread Starter
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284
    Really?! ohh no.... (cryin face)

  4. #4
    Addicted Member djengiz's Avatar
    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    153
    Why are you casting in the first place?

  5. #5
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    its not your celeron, its to do with the way that decimal numbers are stored in memory, not just in VB.

    decimal numbers cannot be represented accuratly in binary basically.

    do a search on here for "floating-point numbers microsoft" and you'll find a nice big discussion about it - quite interesting actually
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  6. #6

    Thread Starter
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284
    umm i cant found i think
    but what can i do to solve my problem, without change the type of "s"?

    help me pls...

  7. #7
    Addicted Member djengiz's Avatar
    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    153
    I learned in school that you can only use so many decimal places as the least number of decimal places. You should round it to 1 decimal place.

    VB Code:
    1. Dim S As Single
    2.     Dim S1 As Integer
    3.     S = 5.2
    4.     S1 = Int(S)
    5.     MsgBox Round(S - S1, 1)

  8. #8

    Thread Starter
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284
    This is an amazing tip , ill make a try!

    Thanks for the answers.

    Jim

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