Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 03-30-2007, 11:39 AM   #1
voidcranium
Registered Something.
 
voidcranium's Avatar
 
Join Date: Oct 2006
Location: Close to: lat 36W, long 94N
Posts: 175
Thanks: 1
Thanked 0 Times in 0 Posts
voidcranium is on a distinguished road
Round() - Can I round DOWN?

I need to have a text box show a number that is rounded down.
Here is the code I have.

This code rounds UP I need it to round DOWN.
Code:
Private Sub cmdCalculate_Click()
txtTotalPacks = Round((txtSheetsRan * [# Up]) / [# in Pack])
This
((2750*2)/1000) = 5.5
needs to be this
((2750*2)/1000) = 5

I want this rounded down so it is 5
We do not ship uneven cartons.

Thanks for any help.

the VOID

voidcranium is offline   Reply With Quote
Old 03-30-2007, 11:48 AM   #2
pbaldy
Wino Moderator
 
pbaldy's Avatar
 
Join Date: Aug 2003
Location: Nevada, USA
Posts: 33,112
Thanks: 13
Thanked 4,076 Times in 4,011 Posts
pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold
Rather than round, you could use the Int() function to grab the integer value of the result.
__________________
Paul
Microsoft Access MVP 2007-2019

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
pbaldy is offline   Reply With Quote
Old 03-30-2007, 02:05 PM   #3
EdFred
knows enough, dangerous
 
EdFred's Avatar
 
Join Date: Mar 2007
Location: West Michigan
Posts: 120
Thanks: 2
Thanked 1 Time in 1 Post
EdFred is on a distinguished road
Quote:
Originally Posted by pbaldy View Post
Rather than round, you could use the Int() function to grab the integer value of the result.

Depending on the numbers Fix() may be a better option.

From the 2007 Help File:

Quote:
MyNumber = Int(99.8) ' Returns 99.
MyNumber = Fix(99.2) ' Returns 99.

MyNumber = Int(-99.8) ' Returns -100.
MyNumber = Fix(-99.8) ' Returns -99.

MyNumber = Int(-99.2) ' Returns -100.
MyNumber = Fix(-99.2) ' Returns -99.
I know, not for this particular instance, but it may turn up in a search function, if anyone uses that on here anymore.


Last edited by EdFred; 03-30-2007 at 02:13 PM.
EdFred is offline   Reply With Quote
The Following User Says Thank You to EdFred For This Useful Post:
April15Hater (11-08-2012)
Old 03-30-2007, 02:10 PM   #4
pbaldy
Wino Moderator
 
pbaldy's Avatar
 
Join Date: Aug 2003
Location: Nevada, USA
Posts: 33,112
Thanks: 13
Thanked 4,076 Times in 4,011 Posts
pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold
You're right; if they ship out negative quantities of cartons.
__________________
Paul
Microsoft Access MVP 2007-2019

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
pbaldy is offline   Reply With Quote
Old 03-30-2007, 02:15 PM   #5
EdFred
knows enough, dangerous
 
EdFred's Avatar
 
Join Date: Mar 2007
Location: West Michigan
Posts: 120
Thanks: 2
Thanked 1 Time in 1 Post
EdFred is on a distinguished road
Quote:
Originally Posted by pbaldy View Post
You're right; if they ship out negative quantities of cartons.
Well, sometimes we "bill" ourselves for a negative amount when I magically find material in inventory. We also ship a negative amount if a customer sends material back.
EdFred is offline   Reply With Quote
Old 04-02-2007, 05:10 AM   #6
voidcranium
Registered Something.
 
voidcranium's Avatar
 
Join Date: Oct 2006
Location: Close to: lat 36W, long 94N
Posts: 175
Thanks: 1
Thanked 0 Times in 0 Posts
voidcranium is on a distinguished road
Thanks guys.
I used the int() and it worked.
voidcranium is offline   Reply With Quote
Old 11-08-2012, 05:30 PM   #7
April15Hater
Accountant
 
Join Date: Sep 2008
Location: Tampa, FL
Posts: 349
Thanks: 6
Thanked 2 Times in 2 Posts
April15Hater is on a distinguished road
Re: Round() - Can I round DOWN?

(Found on a search)

__________________
Access without VBA is like logic without DeMorgan's Rule.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
April15Hater is offline   Reply With Quote
Old 09-11-2019, 09:11 AM   #8
19rallen60
Newly Registered User
 
Join Date: Sep 2019
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
19rallen60 is on a distinguished road
Re: Round() - Can I round DOWN?

How about Microsoft and its cluster of goofballs simply provide RoundUp and RoundDown functions that can be used in a query. SQL server provides a method to do it, so should Access.


I would think the syntax should be:
RoundDown([value],[number of decimal places])

Example1: =RoundDown([MyCost],1). This means values like 2.18, 2.199 or 2.1004 would become 2.1 regardless of the number of decimal places the original value is expressed in.


Example2: =RoundDown([MyCost],0). This means values like 2.18, 2.199 or 2.1004 would become 2.0 regardless of the number of decimal places the original value is expressed in.

Same syntax method for RoundUp

Last edited by 19rallen60; 09-11-2019 at 09:23 AM.
19rallen60 is offline   Reply With Quote
Old 09-11-2019, 09:19 AM   #9
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 4,607
Thanks: 50
Thanked 1,052 Times in 1,033 Posts
theDBguy has a spectacular aura about theDBguy has a spectacular aura about
Re: Round() - Can I round DOWN?

Quote:
Originally Posted by 19rallen60 View Post
How about Microsoft and its cluster of goofballs simply provide RoundUp and RoundDown functions that can be used in a query. SQL server provides a method to do it, so should Access.
Hi. Welcome to AWF! But that would make too much sense.
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is offline   Reply With Quote
The Following User Says Thank You to theDBguy For This Useful Post:
19rallen60 (09-11-2019)
Old 09-12-2019, 01:38 AM   #10
Galaxiom
Super Moderator
 
Join Date: Jan 2009
Location: NSW Australia
Posts: 11,604
Thanks: 89
Thanked 1,492 Times in 1,408 Posts
Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold
Re: Round() - Can I round DOWN?

Care should be taken when rounding down the results of floating point calculations.

When using Int() or Fix() to round down (depending on your definition of "down" in the negative realm), we must be allow for the floating point errors in calculations that aught to be integers but come out at tiny margins below the true result.

There are a few ways to deal with this. We can add or subtract a small buffer which will push the floating point over the integer threshold that it should have been. Or process the value having multiplied it by some orders of magnitude and rounding before performing the calculation and then dividing back down.

But these are fudges. Where precise arithmetic is required, use Decimal or Currency datatypes. These are scaled integers so all calculations are done at higher orders of precision.

Decimal allows the Precision (number of significant digits) and Scale (the number of decimal places) to be set by the user. Currency is a Decimal datatype with the Scale fixed to four decimal places.
Galaxiom is offline   Reply With Quote
Old 09-14-2019, 07:07 AM   #11
apr pillai
Newly Registered User
 
apr pillai's Avatar
 
Join Date: Jan 2005
Location: India
Posts: 677
Thanks: 1
Thanked 107 Times in 95 Posts
apr pillai is on a distinguished road
Send a message via AIM to apr pillai Send a message via Yahoo to apr pillai Send a message via Skype™ to apr pillai
Re: Round() - Can I round DOWN?

The ROUNDDOWN() Access Function Code:
Code:
Public Function ROUNDDOWN(ByVal N As Double, ByVal p As Integer) As Double
Dim S1 As Integer, S2 As Integer

S1 = Sgn(N)
S2 = Sgn(p)
Select Case S1
    Case 1
        Select Case S2
            Case 1
                ROUNDDOWN = (Int(N * (10 ^ p)) / 10 ^ p) * S1
            Case -1
                ROUNDDOWN = Int(N / (10 ^ Abs(p))) * 10 ^ (Abs(p) * Abs(S2))
        End Select
    Case -1
        Select Case S2
            Case 1
                ROUNDDOWN = (Int(Abs(N) * (10 ^ p)) / 10 ^ p) * S1
        End Select
End Select
End Function

__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Learn MS-Access Tips and Tricks)

All responses are based on Access2003/2007
apr pillai is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
need help with expression to round number Luckydvl Queries 5 04-13-2005 12:18 PM
round problem StefanSch Forms 1 03-27-2003 02:36 AM
[SOLVED] How to round a querry DANIEL MIELKE Modules & VBA 4 02-22-2002 07:01 PM
Round in Access please help me edvzimmermann Reports 3 10-16-2001 05:58 PM




All times are GMT -8. The time now is 06:42 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World