Results 1 to 5 of 5

Thread: Rounding a number up to next integer

  1. #1

    Thread Starter
    Lively Member Steve Cain's Avatar
    Join Date
    Sep 2000
    Location
    Wiltshire, UK
    Posts
    105
    I am using VB6 professional and need to round a number up to the next integer. I understand that the Round Function will round down for decimals less than 0.5 and round up for decimals 0.5 or greater. I need to round up to the next integer for all decimal values, no matter how small (or at least to 4 decimal places). I am new to Visual Basic so please bear with me. Any code examples would be very welcome.

    Thanks,

    Steve.

  2. #2
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986

    This will help ya!

    There was a post at 31-8-2000 about the same subject, so take a look at it!

    http://forums.vb-world.net/showthrea...threadid=28747
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  3. #3
    Lively Member
    Join Date
    Apr 2000
    Location
    Rafaela (Argentine)
    Posts
    107
    Try this:

    Code:
    y = Int(x) + IIf(x = Int(x), 0, 1)

  4. #4
    Lively Member
    Join Date
    Aug 2000
    Posts
    125
    I use

    Fix(num + .5)

    if negative number want to round down then

    Fix(num + .5 * Sgn(num))

  5. #5
    Lively Member
    Join Date
    Feb 1999
    Location
    Leicester, UK
    Posts
    123
    Add 0.9999 then truncate

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