Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dividing Numbers Evenly

Status
Not open for further replies.

stretcher012599

Programmer
Nov 26, 2005
11
0
0
US
I am trying to make an error check to notify the user if they try to order an item with a quantity ordered not divisable by the pack quantity. This is what I have so far:

If Request.form("Quantity")/objRS3("CaseQty") <> 1 then
response.write("<font size=2 face=Verdana, Arial, Helvetica, sans-serif>Please select a quantity divisable by the pack quantity.</font>")
response.end
End If

Example: This only works if the ordered quantity is 50 and the case quantity 50. But lets say the pack qty is 50 and the customer orders 150, I want this to be good because it divides evenly. But let's say the pack quantity is 50 and the customer orders 125... I want it to return the error "Please select a quantity divisable by the pack quantity" The pack quantity is stored in the database.

Any suggestions would help.
 
try using mod function...something like this:

Code:
If Request.form("Quantity") mod objRS3("CaseQty") <> 0 then
response.write("<font size=2 face=Verdana, Arial, Helvetica, sans-serif>Please select a quantity divisable by the pack quantity.</font>")
response.end  
End If

-DNG
 
Use integer division and normal division and compare the answers - allow for rounding errors.
Code:
If Abs(Quantity/CaseQty - Quantity\CaseQty) < .001 Then
'it's a whole number of packs
Else
' no it isn't
End If

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Most sites sell multi-packs as a quantity of one and the purchaser recognizes that the multi-pack they order contain x number of the items.
In other words
Bic Pen - Single Part No. 001 $.029 Qty1
Bic Pen - 10 Pack Part No. 002 $2.75 Qty1

If you order two 10 packs you only order a quantity of 2 knowing that gives you 20 pens.

Simplifying for the client is nice but stepping outside of common business practice can also cause confusion.


Stamp out, eliminate and abolish redundancy!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top