Page 1 of 2 12 LastLast
Results 1 to 40 of 43

Thread: Rounding to nearest 25,000

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2005
    Posts
    37

    Rounding to nearest 25,000

    This is not an ordinary rounding issue. Here's what I need to do. I have to round any number up to the nearest 25,000 increment.

    For example:

    124,698 would need to round to 125,000
    126,125 would need to round to 150,000
    1,278,189 would need to round to 1,300,000

    Anyone know of a mathematical formula for doing this? Or any good ideas as to how to accomplish this? THANKS!

  2. #2

  3. #3
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: Rounding to nearest 25,000

    Use an integer division (same as regular division but use \ instead of /). This will ALWAYS round down.

    You'll need to add 1 (to make it a round up) unless it divided exactly (cos then you shouldn't be rounded at all). You check that by using Mod.

    So:-
    [Highlight=VB]
    answer = x\25000
    if answer Mod 25000 > 0 then
    answer = answer + 1
    end if

  4. #4
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Rounding to nearest 25,000

    Something like this:
    (replace with appropriate variables)
    VB Code:
    1. Msgbox Round(124698 /1000) * 1000

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  5. #5

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Rounding to nearest 25,000

    Quote Originally Posted by Pradeep1210
    Something like this:
    (replace with appropriate variables)
    VB Code:
    1. Msgbox Round(124698 /1000) * 1000

    Pradeep
    That doesn't work. eg 134998 -> 135000

  7. #7
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Rounding to nearest 25,000

    If you want 250 to round down, just add 1 to t
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.  Dim x As Long
    5.  Dim t As Long
    6.  x = Val(InputBox("Enter a Number"))
    7.  Do While x <> 0
    8.    t = (x \ 25000) * 25000
    9.    if t=0 then t=t+ 1 ' if you want it rounded up
    10.    MsgBox t
    11.    x = Val(InputBox("Enter a Number"))
    12.  Loop
    13.  End
    14. End Sub

  8. #8
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Rounding to nearest 25,000

    Quote Originally Posted by dglienna
    If you want 250 to round down, just add 1 to t
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.  Dim x As Long
    5.  Dim t As Long
    6.  x = Val(InputBox("Enter a Number"))
    7.  Do While x <> 0
    8.    t = (x \ 25000) * 25000
    9.    if t=0 then t=t+ 1 ' if you want it rounded up
    10.    MsgBox t
    11.    x = Val(InputBox("Enter a Number"))
    12.  Loop
    13.  End
    14. End Sub
    Did someone ask how to round down?

  9. #9
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Rounding to nearest 25,000

    Using my method, 250 would be the nearest 25000, which would be zero
    If he wanted it like that, he'd have to remove the line.
    Numbers up to 24999 would show up as 0.

    If he wants 24999 to point to 25000, then I'd have to rewrite some code.
    My code just finds number of times 25000 goes into the number.

    EDIT: This seems to work

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.  Dim x As Long
    5.  Dim t As Long
    6.  x = Val(InputBox("Enter a Number"))
    7.  Do While x <> 0
    8.    t = (x \ 25000) * 25000
    9.    If Abs(x - t) > 12500 Then
    10.      t = t + 25000
    11.    End If
    12.    MsgBox t
    13.    x = Val(InputBox("Enter a Number"))
    14.  Loop
    15.  End
    16. End Sub

    But it still rounds 500 down to 0, and I wasn't sure if thats what the poster wanted.
    Last edited by dglienna; Sep 14th, 2005 at 12:19 PM.

  10. #10
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Rounding to nearest 25,000

    thumbs up ML............i was abt to post the same thing
    Show Appreciation. Rate Posts.

  11. #11
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Rounding to nearest 25,000

    "Using my method, 250 would be the nearest 25000, which would be zero" ==> What does that mean?

    My code just finds number of times 25000 goes into the number.==> No it doesn't.

  12. #12
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Rounding to nearest 25,000

    Quote Originally Posted by dglienna
    Using my method, 250 would be the nearest 25000, which would be zero
    If he wanted it like that, he'd have to remove the line.
    Numbers up to 24999 would show up as 0.

    If he wants 24999 to point to 25000, then I'd have to rewrite some code.
    My code just finds number of times 25000 goes into the number.

    Well, since the OP said
    Quote Originally Posted by CJD#11
    I have to round any number up to the nearest 25,000 increment.
    And

    Quote Originally Posted by CJD#11
    124,698 would need to round to 125,000
    I would assume that 24999 would point to 25000, as would 250. Or even 1 for that matter. The only time the result should be 0 is if the value is 0 to begin with. At 25001, it becomes 50000. But your solution would still work, by adding 1 to t as you mentioned.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  13. #13
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Rounding to nearest 25,000

    Hmm. I read it before I went out, and posted when I got back. Must have missed that. Thanks.

  14. #14
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Rounding to nearest 25,000

    Quote Originally Posted by MartinLiss
    That doesn't work. eg 134998 -> 135000
    That example rounded it off to nearest 1000.
    Try this:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim nNum As Long, nRound As Long
    3.     nRound = 25000
    4.     nNum = InputBox("Enter Number:")
    5.     MsgBox Round(nNum / nRound) * nRound
    6. End Sub

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  15. #15
    Addicted Member BlueRose's Avatar
    Join Date
    Jan 2002
    Location
    ISTANBUL
    Posts
    245

    Re: Rounding to nearest 25,000

    i think which decimal place you want to round is important, first this must be decided then calculation performed.

    for example if you want to round 124,698 to 125,000
    firstly you must divide number by 1000 and round it
    secondly zeros needed must be added
    You can do while you think that you can do

    If you think my answer solve your question, please rate it.

  16. #16
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Rounding to nearest 25,000

    Quote Originally Posted by FunkyDexter
    Use an integer division (same as regular division but use \ instead of /). This will ALWAYS round down.
    You know what? That's not true. The integer division operator will round to the nearest integer, not always round down.

  17. #17
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Rounding to nearest 25,000

    Quote Originally Posted by Pradeep1210
    That example rounded it off to nearest 1000.
    Try this:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim nNum As Long, nRound As Long
    3.     nRound = 25000
    4.     nNum = InputBox("Enter Number:")
    5.     MsgBox Round(nNum / nRound) * nRound
    6. End Sub

    Pradeep
    No, sorry 35000 -> 25000

  18. #18
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Rounding to nearest 25,000

    Quote Originally Posted by MartinLiss
    "Using my method, 250 would be the nearest 25000, which would be zero" ==> What does that mean?

    My code just finds number of times 25000 goes into the number.==> No it doesn't.
    The first example was rounding down to the nearest 25000

    Using my method, 250 goes into 25000, zero times

    My original code just found number of times a number goes into 25000 if it is over 25000

    My explanatiion was a bit off. Sorry

  19. #19
    New Member wspguy's Avatar
    Join Date
    Sep 2005
    Location
    South Carolina
    Posts
    13

    Re: Rounding to nearest 25,000

    Here, try this...
    VB Code:
    1. Private Function getRnd(ByRef lNumIn As Long, lRnd As Long) As Long
    2.     Dim lNew As Long
    3.     Dim lTmp As Long
    4.    
    5.     On Error GoTo Err_H
    6.     'lNumIn = Number to Round off
    7.     'lRnd   = Control Variable
    8.    
    9.     lTmp = lNumIn Mod lRnd
    10.    
    11.     If lTmp < (lRnd / 2) Then
    12.         lNew = lNumIn - lTmp
    13.     Else
    14.         lNew = lNumIn + (lRnd - lTmp)
    15.     End If
    16.    
    17.     getRnd = lNew
    18. Exit Function
    19. Err_H:
    20.     getRnd = -1
    21. End Function

    I hope I'm on the right track for you.

  20. #20
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Rounding to nearest 25,000

    Quote Originally Posted by MartinLiss
    No, sorry 35000 -> 25000
    That's right.
    35000 is nearer to 25000 than 50000
    The midpoint is 37500. So after this it will round to 50000


    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  21. #21

  22. #22
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Rounding to nearest 25,000

    I don't get it. Why are you all givin new complex answers when Marty showed such a simple brilliant solution in the first reply?

  23. #23
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Rounding to nearest 25,000

    I have this theory that I think has just been further proven by this very thread:
    Ask 10 developers how to do something and you will get 23 different opinions.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  24. #24

    Thread Starter
    Member
    Join Date
    Aug 2005
    Posts
    37

    Re: Rounding to nearest 25,000

    Quote Originally Posted by Joacim Andersson
    I don't get it. Why are you all givin new complex answers when Marty showed such a simple brilliant solution in the first reply?
    Really? I don't see how that would work. And yes, all numbers(regardless of decimal places, which would be 2 b/c all numbers are monetary values) have to be rounded up to the next 25000 increment.

  25. #25
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Rounding to nearest 25,000

    Quote Originally Posted by dglienna
    The first example was rounding down to the nearest 25000

    Using my method, 250 goes into 25000, zero times

    My original code just found number of times a number goes into 25000 if it is over 25000

    My explanatiion was a bit off. Sorry
    You mean 25000 goes into 250 0 times.... 250 will go into 25000 100 times....

    So the logic should be to see how many times 25000 will go into a number....

    The integer division operator will round to the nearest integer, not always round down. -- actualy it goes to the nearest number, unles it's at the break point, in which case it goes to the nearest EVEN integer.

    So Round(1.5) gives you 2, but Round(2.5) also gives 2..... I don't know how many times that caused us greif in our app.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  26. #26
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Rounding to nearest 25,000

    Quote Originally Posted by CJD#11
    Really? I don't see how that would work. And yes, all numbers(regardless of decimal places, which would be 2 b/c all numbers are monetary values) have to be rounded up to the next 25000 increment.
    VB Code:
    1. MsgBox Int(YourNumber) + 25000& - Int(YourNumber) Mod 25000&
    EDIT: That works unless your number is negative in which case you need to subtract 25000 first.
    VB Code:
    1. If YourNumber < 0 Then
    2.     YourNumber = YourNumber - 25000&
    3. End If
    4. MsgBox Int(YourNumber) + 25000& - Int(YourNumber) Mod 25000&
    Last edited by Joacim Andersson; Sep 14th, 2005 at 01:46 PM.

  27. #27

    Thread Starter
    Member
    Join Date
    Aug 2005
    Posts
    37

    Re: Rounding to nearest 25,000

    Quote Originally Posted by techgnome
    So Round(1.5) gives you 2, but Round(2.5) also gives 2..... I don't know how many times that caused us greif in our app.

    -tg
    Been there, done that!

  28. #28
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Rounding to nearest 25,000

    Quote Originally Posted by techgnome
    The integer division operator will round to the nearest integer, not always round down. -- actualy it goes to the nearest number, unles it's at the break point, in which case it goes to the nearest EVEN integer.
    When I claimed that the integer division operator not always will round down. I was talking about the integer division operator (the backslash) not the Round function. Maybe I should elaborate on that, what I mean is that if not both operands are integers VB will first round the operands to the closest integer number before it does the division in which case it rounds down. So for example 17 \ 3 will be 5, meaning it rounds down. But 17.6 \ 3 will become 6, which means that VB first rounds 17.6 to 18 before it does the division.

  29. #29
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Rounding to nearest 25,000

    Quote Originally Posted by MartinLiss
    But as I pointed out to dglienna, the poster wants to round UP.
    Oh! I missed that UP
    Here's the fix:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim nNum As Long, nRound As Long
    3.     nRound = 25000
    4.     nNum = InputBox("Enter Number:")
    5.     If nNum Mod nRound = 0 Then
    6.         MsgBox ((nNum \ nRound)) * nRound
    7.     Else
    8.         MsgBox (1 + (nNum \ nRound)) * nRound
    9.     End If
    10. End Sub
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  30. #30
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Rounding to nearest 25,000

    I still think Marty had the best solution. With the simple fix of using the Int function as I showed above it works perfectly.

  31. #31

    Thread Starter
    Member
    Join Date
    Aug 2005
    Posts
    37

    Re: Rounding to nearest 25,000

    Quote Originally Posted by Pradeep1210
    Oh! I missed that UP
    Here's the fix:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim nNum As Long, nRound As Long
    3.     nRound = 25000
    4.     nNum = InputBox("Enter Number:")
    5.     If nNum Mod nRound = 0 Then
    6.         MsgBox ((nNum \ nRound)) * nRound
    7.     Else
    8.         MsgBox (1 + (nNum \ nRound)) * nRound
    9.     End If
    10. End Sub
    Doing this math using the nubmer 26,000, the end result was 51000, which would not meet my needs. It would need to = 50,000. Or did I look at that wrong?

  32. #32
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Rounding to nearest 25,000

    Quote Originally Posted by CJD#11
    Doing this math using the nubmer 26,000, the end result was 51000, which would not meet my needs. It would need to = 50,000. Or did I look at that wrong?
    To me it gives 50000

    Did you copy the code exactly as it is ?

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  33. #33

    Thread Starter
    Member
    Join Date
    Aug 2005
    Posts
    37

    Re: Rounding to nearest 25,000

    O.k., lets back off a little. Forget the whole 25000 thing. How about just a way to round any number UP every time?

    Ex 4.1 = 5
    4.3 = 5
    4.6 = 5
    5.1 = 6

    From what I've read, there is no VB command to do this, so it has to be 'forced' to happen.

  34. #34
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Rounding to nearest 25,000

    I still don't get it... CJD#11 did you even try this out?
    VB Code:
    1. MsgBox Int(YourNumber) + 25000& - Int(YourNumber) Mod 25000&

  35. #35
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Rounding to nearest 25,000

    Quote Originally Posted by CJD#11
    O.k., lets back off a little. Forget the whole 25000 thing. How about just a way to round any number UP every time?

    Ex 4.1 = 5
    4.3 = 5
    4.6 = 5
    5.1 = 6

    From what I've read, there is no VB command to do this, so it has to be 'forced' to happen.
    MsgBox Int(theNumber) + 1

  36. #36
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Rounding to nearest 25,000

    Stupid timeouts..... accidently double posted.....
    Plz disregard.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  37. #37

    Thread Starter
    Member
    Join Date
    Aug 2005
    Posts
    37

    Re: Rounding to nearest 25,000

    Quote Originally Posted by Pradeep1210
    To me it gives 50000

    Did you copy the code exactly as it is ?

    Pradeep

    AHHHH, o.k. that did work.

    I did the math out by hand, not using the code.

  38. #38
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Rounding to nearest 25,000

    Quote Originally Posted by Joacim Andersson
    MsgBox Int(theNumber) + 1
    It should be :
    VB Code:
    1. If Int(theNumber) = theNumber Then
    2.     MsgBox theNumber
    3. Else
    4.     MsgBox Int(theNumber) + 1
    5. End If

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  39. #39
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Rounding to nearest 25,000

    Not if you want to round up every number.

  40. #40
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Rounding to nearest 25,000

    Quote Originally Posted by Joacim Andersson
    When I claimed that the integer division operator not always will round down. I was talking about the integer division operator (the backslash) not the Round function. Maybe I should elaborate on that, what I mean is that if not both operands are integers VB will first round the operands to the closest integer number before it does the division in which case it rounds down. So for example 17 \ 3 will be 5, meaning it rounds down. But 17.6 \ 3 will become 6, which means that VB first rounds 17.6 to 18 before it does the division.
    I was smoking something when I wrote that.... the air has now cleared and I don't know *what* I was thinking.... but what will VB do to 18.5 vs 17.5 before doing int division?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Page 1 of 2 12 LastLast

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