Problem rounding down Access 2000

P

Pastor Del

The abridged version:
I want to divide an odd whole number by 2 and deal seperately with the
quotient as a whole number & remainder as a decimal. If I use integers to
perform the calculations the quotient is wrong because it automatically
rounds up. (Sample code at bottom) How can I get the quotient to round down?

The detailed version:
I have build an application to generate travelers for my company. A
traveler accompanies our products through the manufacturing process. The
first traveler is always the sample traveler. Each traveler after that has a
traveler quantity that varies from product to product. My application
calculates the number of travelers for a particular production run by
subtracting the sample quantity from the kit quantity and then dividing the
difference by the traveler quantity for this particular product. A problem
arises when the difference mentioned above is an odd number and the traveler
quantity is 2.

With the following quantities I want my code to generate 1 sample traveler
with a quantity of 1, 249 travelers with a quantity of 2 each and a final
traveler with a quantity of 1. But because the quotient is rounded up it
generates 250 travelers with traveler quantity of 2 each.

Dim intKitQty as Integer, intSampleQty as integer, intDifference as Integer
Dim intTravelerQty as Integer, intQtyOfTravelers, intLastTravelerQty as
integer

intKitQty = 500
intSamplQty = 1
intTravelerQty = 2
intDifference = intKitQty - intSampleQty
intQtyOfTravelers = intDifference / intTravelerQty
intLastTravelerQty = intDifference Mod intTravelerQty

How can I get the intQtyOfTravelers to round down?
 
J

Jeff Boyce

Take a look at "integer division", which uses the "\" instead of the "/".

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
 
J

John Spencer

Take a look at the INT function and Fix functions.

Int(SomeNumber) rounds down to the nearest integer. So negative number round
away from zero
Fix(SomeNumber) rounds to the nearest integer towards zero. So negative
numbers round toward zero.



John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top