Results 1 to 3 of 3

Thread: [2005] CInt Rounding

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fox, OK
    Posts
    381

    [2005] CInt Rounding

    Why does CInt(90.5) round DOWN to 90? We've always been taught that if it's 0.5 or more, round up!

    vb Code:
    1. MessageBox.Show("90.1 gets rounded to " & CInt(90.1) & vbCrLf & "90.5 gets rounded to " & CInt(90.5) & vbCrLf & "90.51 gets rounded to " & CInt(90.51) & vbCrLf & "90.8 gets rounded to " & CInt(90.8))

  2. #2
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [2005] CInt Rounding

    use Math.Round

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] CInt Rounding

    As always, visiting the MSDN documentation first should be the way to find information. The documentation for the CInt function has this to say:
    If the fractional part is exactly 0.5, the integer conversion functions round it to the nearest even integer. For example, 0.5 rounds to 0, and 1.5 and 2.5 both round to 2. This is sometimes called banker's rounding, and its purpose is to compensate for a bias that could accumulate when adding many such numbers together.
    A quick look at the documentation for the Math.Round method reveals that it uses banker's rounding too.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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