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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rounding Up 4

Status
Not open for further replies.

nayfeh

Programmer
Mar 13, 2002
163
CA
Hi,

Is there a function that round values up?
So, in the example below I'd like the variable lngTotPallets rounded up to the nearest "1". So, now if there a total that's less that 0.5 it would round to 0 instead of 1.

lngTotPallets = Round((intTotalQty / 108), 0)

Thanks in advance.

TN
 
Hi TN!

Try this:

If intTotalQty Mod 108 < 54 Then
lngTotPallets = Round((intTotalQty / 108), 0) + 1
Else
lngTotPallets = Round((intTotalQty / 108), 0)
End If

hth
Jeff Bridgham
bridgham@purdue.edu
 
Off the top of my head:

lngTotPallets = CLng(Me!intTotalQty / 108)

Let me know if it doesn't work.
 
Thanks guys!!! I tried both ways, jebry's way worked. CLng didn't work, it still rounded down to zero.


TN
 
I don't think the Round function is 100% fool proof.
Round(9.99,0) rounds to 10 + 1 = 11 and I don't think that's what you want.
You could try
lngTotPallets = Int(intTotalQty / 108)+1

or you could use

lngTotPallets = -1 * Int(-1 *(intTotalQty / 108))

Either of those should be OK. I prefer the second one myself but it's your call.

Paul

 
Hi - i'm interested in using the Round function, but don't seem to have the correct reference - Please could someone tell me what reference I have to add, since it may take some time churning through them all...

(when i use the other functions I always end up with 0 or 1 as my rounded value, even when i enter 10 as my original number - something to do with dividing by 108)
 
Fred, what version of Access are you running? I don't think that 97 has the Round Function in it. What other functions have you tried.

Paul
 
I'm using 97 - that would be the reason then...

I have found a round function on
but it doesn't seem to work - i'm just working through all the different functions to make one up myself.

I'm trying to find a way to simply get the decimal value, so if it's 4.9 it should return 0.9 - I can try and work with that value then, but don't think that's possible.

Any ideas would be grateful
 
If all you want it the decimal value then you can use this

([YourNumberField] - Int([YourNumberField])

4.9 becomes .9
5.2 becomes .2
43.12345 becomes .12345

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top