Results 1 to 4 of 4

Thread: Int - converting to integer?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    3

    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.

  2. #2
    Lively Member
    Join Date
    Aug 2006
    Posts
    72

    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
    VB Code:
    1. Dim Numbers as Single

  3. #3
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    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.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    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
  •  



Click Here to Expand Forum to Full Width