|
-
Nov 18th, 2006, 08:37 PM
#1
Thread Starter
New Member
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.
-
Nov 18th, 2006, 09:08 PM
#2
Lively Member
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
-
Nov 18th, 2006, 09:21 PM
#3
Re: Int - converting to integer?
 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.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Nov 19th, 2006, 10:43 AM
#4
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.
My usual boring signature: Nothing
 
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
|