473,396 Members | 1,748 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,396 software developers and data experts.

Ceiling function

Ericks
74
I have a calculated field in a report that states: =Sum([Product Need])
How can I have it round up to the nearest 50. In Excel I use (ceiling(cel;50)). How would that be in Access? I tried =ceiling(Sum([Product Need]);50) but that doesn't work.
Aug 25 '08 #1
9 20978
PianoMan64
374 Expert 256MB
I have a calculated field in a report that states: =Sum([Product Need])
How can I have it round up to the nearest 50. In Excel I use (ceiling(cel;50)). How would that be in Access? I tried =ceiling(Sum([Product Need]);50) but that doesn't work.
You would creating a function that would do the same thing as ceiling in Excel.

But since you only need it to round to the closes 50 cents, then you would simply leave out the Significance options out the function.

for Example:

Expand|Select|Wrap|Line Numbers
  1. Public Function Ceiling(RoundValue As Currency) As Currency
  2.     Dim TheValue As Currency
  3.     TheValue = RoundValue
  4.     Select Case TheValue - Int(TheValue)
  5.         Case Is <= 0.25
  6.             Ceiling = Int(TheValue)
  7.         Case Is >= 0.5
  8.             Ceiling = Int(TheValue) + 1
  9.         Case Is >= 0.26
  10.             Ceiling = Int(TheValue) + 0.5
  11.     End Select
  12. End Function
  13.  
  14.  
Then you would copy and paste this into a new module that will hold this public function that you can use anywhere in your application.

If you need any more help, let me know,

Hope that helps,

Joe P.
Aug 25 '08 #2
Ericks
74
You would creating a function that would do the same thing as ceiling in Excel.

But since you only need it to round to the closes 50 cents, then you would simply leave out the Significance options out the function.

for Example:

Expand|Select|Wrap|Line Numbers
  1. Public Function Ceiling(RoundValue As Currency) As Currency
  2.     Dim TheValue As Currency
  3.     TheValue = RoundValue
  4.     Select Case TheValue - Int(TheValue)
  5.         Case Is <= 0.25
  6.             Ceiling = Int(TheValue)
  7.         Case Is >= 0.5
  8.             Ceiling = Int(TheValue) + 1
  9.         Case Is >= 0.26
  10.             Ceiling = Int(TheValue) + 0.5
  11.     End Select
  12. End Function
  13.  
  14.  
Then you would copy and paste this into a new module that will hold this public function that you can use anywhere in your application.

If you need any more help, let me know,

Hope that helps,

Joe P.
Thanks Joe. Actually, it's for whole numbers like 21, 43, 95, 110, etc. that have to be rounded like respectively 50, 50, 100 and 150.
Does that mean I should adapt your code by writing for example 25 instead of 0.25?
Aug 25 '08 #3
Stewart Ross
2,545 Expert Mod 2GB
Hi. For whole numbers the following function implements a general approach to the 'round to nearest X' requirement:

Expand|Select|Wrap|Line Numbers
  1. Public Function RoundToNearestMultiple(lngWholeNoIn As Long, lngToNearest As Long) As Long
  2.     RoundToNearestMultiple = lngToNearest * Int(lngWholeNoIn / lngToNearest)
  3. End Function
Sample results:
Expand|Select|Wrap|Line Numbers
  1. X = RoundToNearestMultiple(80, 50) ==> X = 50
  2. X = RoundToNearestMultiple(2001, 50) ==> X = 2000
  3. X = RoundToNearestMultiple(2001, 100) ==> X = 2000
  4. X = RoundToNearestMultiple(2121, 100) ==> X = 2100
  5. X = RoundToNearestMultiple(2121, 20) ==> X = 2120
Aug 25 '08 #4
FishVal
2,653 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. Public Function RoundToNearestMultiple(lngWholeNoIn As Long, lngToNearest As Long) As Long
  2.     RoundToNearestMultiple = lngToNearest * Int(lngWholeNoIn / lngToNearest)
  3. End Function
It would be better to use Round() function instead of Int().
Though it itself a little weird beast.

Regards,
Fish
Aug 25 '08 #5
missinglinq
3,532 Expert 2GB
How about:

iif([TheValue] mod 50=0, [TheValue], [TheValue]\50)*50 + 50)

21 = 50
43 = 50
95 = 100
110 = 150

Linq ;0)>
Aug 25 '08 #6
Stewart Ross
2,545 Expert Mod 2GB
Hi all. Sometimes I just catch myself completely missing the silliest things - such as the need to round up the value. How did I manage to miss that? Easy modulo arithmetic - but an incorrect result. Dear oh dear...

Anyway, thanks guys for spotting my mistook.

-Stewart
Aug 25 '08 #7
Ericks
74
How about:

iif([TheValue] mod 50=0, [TheValue], [TheValue]\50)*50 + 50)

21 = 50
43 = 50
95 = 100
110 = 150

Linq ;0)>
Exciting discussion. I'm currently traveling but will implement the suggestion ASAP. Will get back to you guys.

Thanks a bunch.
Aug 26 '08 #8
FishVal
2,653 Expert 2GB
Even simpler:
Expand|Select|Wrap|Line Numbers
  1. -50*Int(-[TheValue]/50)
  2.  
Regards,
Fish

P.S. BTW I recall a thread there it was already discussed.
Aug 26 '08 #9
Ericks
74
Even simpler:
Expand|Select|Wrap|Line Numbers
  1. -50*Int(-[TheValue]/50)
  2.  
Regards,
Fish

P.S. BTW I recall a thread there it was already discussed.

OK, I used this code in my report and it works. Fantastic. Thanks a lot for this.
Aug 26 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: pauldepstein | last post by:
I am writing a program which will use the ceiling and floor of square roots. If a positive integer is an exact square (and is not overly huge), does sqrt return an integer-valued real? Or...
3
by: Agnes | last post by:
my number is 100.1 , Now I only want to get 100 without any round up or round down function, Can anyone told me which function can do that ? Thanks
4
by: Ryan Liu | last post by:
Is there a good reason that Decimal does not have Ceiling() method, only Math class has? Thanks!
6
by: Jon Vaughan | last post by:
Can someone tell me why the following statement gives me the result of 0 : Math.Ceiling( 1 / 12); Well actually the above is simplefied from : private const int LocationsPerPage = 12; ...
2
by: AdINo | last post by:
Could anyone help me out on how to use the function floor and ceiling pls
2
by: deanoooo812 | last post by:
I have an Access query (written in MS Access 2000 - thats all we've got - don't get me started on that topic...) for making pharmacy dispensing labels based on an extract from an automated dispensing...
5
by: matthias s | last post by:
Hi there, I believed that Math.Ceiling is like Math.Round except that it always rounds up to the next but this double d = Math.Ceiling(29/15);
15
by: Alasdair | last post by:
I need to apply the ceiling function to arbitrary sized (long) integers. However, division automatically returns the type of its operands, so that, for example: math.ceil(7/4) returns 1. I can use...
1
by: Greenwood | last post by:
Hi Im trying to Math.Ceiling with the following code, where fr is a array of doubles and max is an int, it give me the following error "Error The call is ambiguous between the following methods or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.