Results 1 to 6 of 6
  1. #1
    jlgray0127 is offline Competent Performer
    Windows 7 64bit Access 2003
    Join Date
    Oct 2011
    Location
    Central Illinois
    Posts
    187

    Rounding numbers

    I am trying to round an expression to a multiple of another field.

    Example would be... I have a column which is ([Stocked_Units]-[Demanded_Units]) = column [Variance]
    I want to add a column that looks at the standard pack qty of a box, [Std_Pk_Qty] and the Variance to give me the number of boxes to put in my rack. So...

    We currently keep 300 pc's on the rack, which pack 100 in a box. This would be 3 boxes. Demand is at 312 pcs, so I want the new calculation to tell me to stock 4 boxes to cover my demand.
    Same thing for this

    We currently keep 300 pcs on the rack, and demand is now 198. Pack qty is 100. I want it to tell me that I need to put 2 boxes on the rack now, instead of 3.



    I want it to round up to the Standard Pack qty, which can be any number... It all depends on what the product is. Std pack could be 3, 17, 23, or even 4000. That is why I need it to look at the [Std_Pk_Qty] to the multiple.

    Thanks in advance!

  2. #2
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Something like this?

    for x = 1 to 100
    if (demand / qtyperbox) < (packqty * x) Then
    Boxesreqd = packqty
    exit for
    endif
    next x

    Totally untested!

  3. #3
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Oops - should be Boxesreqd = packqty * x

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    This may offer another approach.

    From Allen Browne's site

    Rounding up

    Rounding up To round upwards towards the next highest number, take advantage of the way Int() rounds negative numbers downwards, like this:
    - Int( - [MyField])
    As shown above, Int(-2.1) rounds down to -3. Therefore this expression rounds 2.1 up to 3.

  5. #5
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    My version:
    Code:
    Public Function MyRound(pDemand As Variant, pQnty As Integer) As Integer
    'pDemand is Demanded Units
    'pQnty is standard pack qty of a box
    '
    ' returns the number of boxes to stock to cover demand
    
       MyRound = Int(pDemand / pQnty) - ((pDemand Mod pQnty) > 0)
    
    End Function

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    You could alter the MyRound line to


    MyRound = -Int( -pDemand / pQnty)

    but either way answers the poster's question.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 11-29-2011, 08:43 AM
  2. rounding down
    By markcranmer in forum Queries
    Replies: 1
    Last Post: 10-11-2011, 09:43 AM
  3. Rounding
    By BLD21 in forum Reports
    Replies: 5
    Last Post: 06-20-2011, 01:06 PM
  4. Expression rounding
    By Scorpio11 in forum Queries
    Replies: 2
    Last Post: 03-07-2011, 01:29 PM
  5. Rounding off
    By Alex Motilal in forum Access
    Replies: 4
    Last Post: 12-20-2009, 12:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums