|
-
Jul 17th, 2007, 12:18 AM
#1
Thread Starter
Hyperactive Member
[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:
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))
-
Jul 17th, 2007, 12:30 AM
#2
-
Jul 17th, 2007, 01:56 AM
#3
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|