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.
9 20978
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: -
Public Function Ceiling(RoundValue As Currency) As Currency
-
Dim TheValue As Currency
-
TheValue = RoundValue
-
Select Case TheValue - Int(TheValue)
-
Case Is <= 0.25
-
Ceiling = Int(TheValue)
-
Case Is >= 0.5
-
Ceiling = Int(TheValue) + 1
-
Case Is >= 0.26
-
Ceiling = Int(TheValue) + 0.5
-
End Select
-
End Function
-
-
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.
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: -
Public Function Ceiling(RoundValue As Currency) As Currency
-
Dim TheValue As Currency
-
TheValue = RoundValue
-
Select Case TheValue - Int(TheValue)
-
Case Is <= 0.25
-
Ceiling = Int(TheValue)
-
Case Is >= 0.5
-
Ceiling = Int(TheValue) + 1
-
Case Is >= 0.26
-
Ceiling = Int(TheValue) + 0.5
-
End Select
-
End Function
-
-
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?
Hi. For whole numbers the following function implements a general approach to the 'round to nearest X' requirement: - Public Function RoundToNearestMultiple(lngWholeNoIn As Long, lngToNearest As Long) As Long
-
RoundToNearestMultiple = lngToNearest * Int(lngWholeNoIn / lngToNearest)
-
End Function
Sample results: - X = RoundToNearestMultiple(80, 50) ==> X = 50
-
X = RoundToNearestMultiple(2001, 50) ==> X = 2000
-
X = RoundToNearestMultiple(2001, 100) ==> X = 2000
-
X = RoundToNearestMultiple(2121, 100) ==> X = 2100
-
X = RoundToNearestMultiple(2121, 20) ==> X = 2120
- Public Function RoundToNearestMultiple(lngWholeNoIn As Long, lngToNearest As Long) As Long
-
RoundToNearestMultiple = lngToNearest * Int(lngWholeNoIn / lngToNearest)
-
End Function
It would be better to use Round() function instead of Int().
Though it itself a little weird beast.
Regards,
Fish
How about:
iif([TheValue] mod 50=0, [TheValue], [TheValue]\50)*50 + 50)
21 = 50
43 = 50
95 = 100
110 = 150
Linq ;0)>
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
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.
Even simpler:
Regards,
Fish
P.S. BTW I recall a thread there it was already discussed.
Even simpler:
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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
|
by: Ryan Liu |
last post by:
Is there a good reason that Decimal does not have Ceiling() method, only
Math class has?
Thanks!
|
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;
...
|
by: AdINo |
last post by:
Could anyone help me out
on how to use the function floor and ceiling pls
|
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...
|
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);
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
| |