Rounding up by a specific increment...?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sox Fan in CT

    Rounding up by a specific increment...?

    I have a wall product that is made in 4' wide increments. The product
    is sold by the foot. A customer may order 38 feet but they will
    actually receive 4 sections for a total of 40 feet. (they would then
    field cut it to fit....)

    In order to provide a shipping quote, I have to calculate a weight.
    The weight table for this item lists a weight per 4' section. So what
    I was trying to do was divide the order qty by a UOM_factor which in
    this case is 4 and then multiplying that times the 4' section weight.
    This works but only if the ordered qty is actually in a multiple of 4.

    i.e.
    item weight per 4 ft: 10 lbs
    order qty = 80 feet
    uom_factor= 4
    80 / uom_factor = 20
    20 * 10lbs = 200lbs WORKS OK !

    order qty = 77 feet
    77 / uom_factor = 19.25
    19.25 * 10 = 192.50lbs NO GOOD because even though they
    only "ordered" 77 feet they would receive 80 feet.

    How can I make it round "up" to the nearest increment of 4 in order to
    capture the "true" shipping weight?

    Thanks for any suggestions....

  • Janross

    #2
    Re: Rounding up by a specific increment...?

    I use the following function, which Arvin Meyer posted a long time ago in this
    newsgroup. Note that I'm copying from a db I use, so I may have made minor
    adjustments for my own application. But it should get you on the right track.

    Beware of weird line wraps.

    HTH.

    Jan

    Function Rnd2Num(Amt As Variant, RoundAmt As Variant, Direction As Integer) As
    Double
    'From: Arvin Meyer
    'Newsgroups: comp.Databases. ms -Access
    'Date: 1999/04/21


    'Use it in your textbox's controlsource like:
    '=Rnd2Num([Forms]![frmWhatever]![yearprice],1,1)


    On Error Resume Next
    Dim Temp As Double
    Temp = Amt / RoundAmt
    If Int(Temp) = Temp Then
    Rnd2Num = Amt
    Else
    If Direction = rnddown Then
    Temp = Int(Temp)
    Else
    Temp = Int(Temp) + 1
    End If
    Rnd2Num = Temp * RoundAmt
    End If
    End Function




    [color=blue]
    >How can I make it round "up" to the nearest increment of 4 in order to
    >capture the "true" shipping weight?
    >[/color]


    Jan Stempel
    Stempel Consulting

    Comment

    • Phil Stanton

      #3
      Re: Rounding up by a specific increment...?

      Try

      If OrderQty \ UOM_factor = OrderQty / UOM_factor then ' Integer
      division = ordinary division
      QtyToSend = OrderQty
      Else
      QtyToSend = (OrderQty \ UOM_factor + 1) / UOM_factor ' Round up to
      nerest 4 feet
      End If

      Phil
      <Sox Fan in CT> wrote in message
      news:23a7ed3512 1e1f79483ac3999 ca14261@news.te ranews.com...[color=blue]
      > I have a wall product that is made in 4' wide increments. The product
      > is sold by the foot. A customer may order 38 feet but they will
      > actually receive 4 sections for a total of 40 feet. (they would then
      > field cut it to fit....)
      >
      > In order to provide a shipping quote, I have to calculate a weight.
      > The weight table for this item lists a weight per 4' section. So what
      > I was trying to do was divide the order qty by a UOM_factor which in
      > this case is 4 and then multiplying that times the 4' section weight.
      > This works but only if the ordered qty is actually in a multiple of 4.
      >
      > i.e.
      > item weight per 4 ft: 10 lbs
      > order qty = 80 feet
      > uom_factor= 4
      > 80 / uom_factor = 20
      > 20 * 10lbs = 200lbs WORKS OK !
      >
      > order qty = 77 feet
      > 77 / uom_factor = 19.25
      > 19.25 * 10 = 192.50lbs NO GOOD because even though they
      > only "ordered" 77 feet they would receive 80 feet.
      >
      > How can I make it round "up" to the nearest increment of 4 in order to
      > capture the "true" shipping weight?
      >
      > Thanks for any suggestions....
      >[/color]


      Comment

      Working...