Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2006
    Posts
    5

    Lightbulb Unanswered: Rounding numbers

    I will make this short (beginner here). I am working with numbers that I would like to round up to the nearest thousands or so. Like 28,230 to 28,000 or 134,634 to 135,000, I have seen the round function but it is not working for me. Any help would be great.

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    dim MyLong As Long, Remainder As Integer

    MyLong=123,456
    Remainder=MyLong MOD 1000
    MyLong=MyLong+IIf(Remainder>500,1000,0)
    MyLong=CLng(MyLong/1000)*1000


    Next question ...
    Back to Access ... ADO is not the way to go for speed ...

  3. #3
    Join Date
    Mar 2006
    Posts
    5
    Thank you very much, that was fast.... I will get it a try.

  4. #4
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Oops! Check the last line:

    MyLong=CLng(MyLong/1000)*1000

    Should be:

    MyLong=CLng(MyLong \ 1000)*1000

    The 1st will promote the rounding up ... Real Division
    The latter will truncate the remainder ... Integer Division

    Whew!
    Back to Access ... ADO is not the way to go for speed ...

  5. #5
    Join Date
    Mar 2006
    Posts
    5
    Ok, great...

  6. #6
    Join Date
    Mar 2006
    Posts
    5
    I must be doing something wrong I keep getting Expected: End of Statement error. ???? The first part MyLong=123,456 is highlited in red. ? Sorry I'm not to good at this.

  7. #7
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    I've just been playing with Mike's function too He just Inspired a little vbRound function that allows rounding either side of the decimal place. Thanks for the idea Mike!

    Anyhoo - remove the comma.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  8. #8
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by mustgo35
    I must be doing something wrong I keep getting Expected: End of Statement error. ???? The first part MyLong=123,456 is highlited in red. ? Sorry I'm not to good at this.
    My bad. Difference between what you display (to read) and what you type to work (program) ...

    Pootle hit it right on the head (was that 1 lump or 2?)... Remove that comma.

    Should be: 123456
    Back to Access ... ADO is not the way to go for speed ...

  9. #9
    Join Date
    Mar 2006
    Posts
    5
    Thanks guys!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •