Int - converting to integer?
Does Int always round down to the nearest integer? I run a program and it will convert, say 15.9999, to 15 or 100.9999 to 100. I'm confused because my professor told me that it would round up or down to the nearest integer but I'm finding out otherwise on my own since it's always rounding down.
Re: Int - converting to integer?
Well 15.999 is a Single(Float) so if you use Integer it will round according to the heximal system.
Could be more to it.
So for 15.002100123 use
Re: Int - converting to integer?
Quote:
Originally Posted by phoncole
Does Int always round down to the nearest integer? I run a program and it will convert, say 15.9999, to 15 or 100.9999 to 100. I'm confused because my professor told me that it would round up or down to the nearest integer but I'm finding out otherwise on my own since it's always rounding down.
Int is a legacy function from VB6. It doesn't round per say, it simply cuts off the decimal part of a number. In .NET you should use the Math.Round function.
Re: Int - converting to integer?
The rounding your prof was discussing is called "Bankers Rounding". Some rounding techniques use it, others don't, and Int will just drop the decimal, as already noted. If you search this forum on Bankers Rounding, you will find a few discussions about this, but there aren't all that many threads about it. I don't think I've seen one for a couple months. It seemed to have been discussed more in VB6.