473,320 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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....

Nov 12 '05 #1
2 4242
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


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

Jan Stempel
Stempel Consulting
Nov 12 '05 #2
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:23******************************@news.teranew s.com...
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....

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jeff Boes | last post by:
(asked last week on .questions, no response) Can anyone explain why this happens? (under 7.4.1) select '2004-05-27 09:00:00.500001-04' :: timestamp(0) ; timestamp ---------------------...
29
by: Marco | last post by:
Hello, I have : float f = 36.09999999; When I do : char cf; sprintf(cf,"%0.03lf", f); I get : 36.100
13
by: Shirsoft | last post by:
I have a 32 bit intel and 64 bit AMD machine. There is a rounding error in the 8th digit. Unfortunately because of the algorithm we use, the errors percolate into higher digits. C++ code is...
6
by: abcd | last post by:
I am trying to write a rounding function. Rounding to 0.05. e.g. I should get below results 6.125 --6.15 1.699 --1.7 1.1985 --1.20 0.5625 --0.60 Can someone have any sample for...
15
by: Mukesh_Singh_Nick | last post by:
Why does floating point have a rounding error? How to work around it? For example, the following: flaot f = 1234.12345678F; printf("%2f\n", f) //prints 1234.123413 and
18
by: jdrott1 | last post by:
i'm trying to round my currency string to end in 9. it's for a pricing application. this is the function i'm using to get the item in currency: FormatCurrency(BoxCost, , , , TriState.True) if...
5
by: Spoon | last post by:
Hello everyone, I don't understand how the lrint() function works. long lrint(double x); The function returns the nearest long integer to x, consistent with the current rounding mode. It...
206
by: md | last post by:
Hi Does any body know, how to round a double value with a specific number of digits after the decimal points? A function like this: RoundMyDouble (double &value, short numberOfPrecisions) ...
20
by: jacob navia | last post by:
Hi "How can I round a number to x decimal places" ? This question keeps appearing. I would propose the following solution #include <float.h> #include <math.h>
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.