473,508 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Rounding

7 New Member
I have a Start and End time in a table which I find the total time by using
diff: (DateDiff("n",[Start],[End]))

I then want to round this figure up to the nearest 15mins (billing period).
I tried
rounddif: CInt([diff]/15)*15
but it rounds up or down to the nearest 15. I want to force it to always round up.
eg. 6min would round to 15, 33mins would round to 45, etc

Any help would be greatly appreciated.

I am using MS Access 2007
Sep 19 '07 #1
13 4101
FishVal
2,653 Recognized Expert Specialist
I have a Start and End time in a table which I find the total time by using
diff: (DateDiff("n",[Start],[End]))

I then want to round this figure up to the nearest 15mins (billing period).
I tried
rounddif: CInt([diff]/15)*15
but it rounds up or down to the nearest 15. I want to force it to always round up.
eg. 6min would round to 15, 33mins would round to 45, etc

Any help would be greatly appreciated.

I am using MS Access 2007
Hi, tmdan.

Try this
rounddif: Round([diff]/15)*15
Sep 19 '07 #2
tmdan
7 New Member
Hi, thanks for that but it still returns the same result.

Any other ideas?
Sep 21 '07 #3
ADezii
8,834 Recognized Expert Expert
Hi, thanks for that but it still returns the same result.

Any other ideas?
This little Function will perform the proper 'Round Up at 15 min. Intervals' for a differential of up to 2 hours:
Expand|Select|Wrap|Line Numbers
  1. Public Function fRoundUpTo15(MinDiff As Integer) As Integer
  2. Select Case MinDiff
  3.   Case 1 To 15
  4.     fRoundUpTo15 = 15
  5.   Case 16 To 30
  6.     fRoundUpTo15 = 30
  7.   Case 31 To 45
  8.     fRoundUpTo15 = 45
  9.   Case 46 To 60
  10.     fRoundUpTo15 = 60
  11.   Case 61 To 75
  12.     fRoundUpTo15 = 75
  13.   Case 76 To 90
  14.     fRoundUpTo15 = 90
  15.   Case 91 To 105
  16.     fRoundUpTo15 = 105
  17.   Case 106 To 120
  18.     fRoundUpTo15 = 120
  19. End Select
  20. End Function
Expand|Select|Wrap|Line Numbers
  1. "A time difference of 63 minutes Rounds Up to: " & fRoundUpTo15(63) & " minutes"
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. A time difference of 63 minutes Rounds Up to: 75 minutes
Sep 21 '07 #4
ADezii
8,834 Recognized Expert Expert
Hi, thanks for that but it still returns the same result.

Any other ideas?
Actually, I like my 2nd idea better:
Expand|Select|Wrap|Line Numbers
  1. Dim diff As Integer, diffRoundUp As Integer
  2.  
  3. If diff Mod 15 = 0 Then
  4.   diffRoundUp = diff
  5. Else
  6.   diffRoundUp = diff + (15 - (diff Mod 15))
  7. End If
Sep 21 '07 #5
tmdan
7 New Member
Actually, I like my 2nd idea better:
Expand|Select|Wrap|Line Numbers
  1. Dim diff As Integer, diffRoundUp As Integer
  2.  
  3. If diff Mod 15 = 0 Then
  4.   diffRoundUp = diff
  5. Else
  6.   diffRoundUp = diff + (15 - (diff Mod 15))
  7. End If
Sorry, I'm a bit of a novice with VB so I was trying to acheive this with a query.

I have a text box on my form called diff with =(DateDiff("n",[Start],[End])) as the control source.

I have created a second text box called diffRoundUp but where do I put this code so that this box displays the rounded figure?

Thanks again for your help
Oct 2 '07 #6
ADezii
8,834 Recognized Expert Expert
Sorry, I'm a bit of a novice with VB so I was trying to acheive this with a query.

I have a text box on my form called diff with =(DateDiff("n",[Start],[End])) as the control source.

I have created a second text box called diffRoundUp but where do I put this code so that this box displays the rounded figure?

Thanks again for your help
Placing this code in your Form's Current() Event should do the trick:[
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. If Not Me.NewRecord And Not IsNull(Me![Start]) And Not IsNull(Me![End]) Then                                          '*
  3.   Dim intMinDiff As Integer
  4.  
  5.   intMinDiff = DateDiff("n", Me![Start], Me![End])
  6.  
  7.   If intMinDiff Mod 15 = 0 Then
  8.     Me![diffRoundUp] = intMinDiff
  9.   Else
  10.     Me![diffRoundUp] = intMinDiff + (15 - (intMinDiff Mod 15))
  11.   End If
  12. Else
  13.   Me![diffRoundUp] = Null
  14. End If
  15. End Sub
Oct 2 '07 #7
FishVal
2,653 Recognized Expert Specialist
Hi, tmdan.

You may advantageously use Int() function that always rounds down.
rounddif: -Int(-[diff]/15)*15
Oct 2 '07 #8
tmdan
7 New Member
Hi, tmdan.

You may advantageously use Int() function that always rounds down.
rounddif: -Int(-[diff]/15)*15
Thanks, but I want to always round up. Do you know of a variation of it to go up?
Oct 2 '07 #9
tmdan
7 New Member
Placing this code in your Form's Current() Event should do the trick:[
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. If Not Me.NewRecord And Not IsNull(Me![Start]) And Not IsNull(Me![End]) Then                                          '*
  3.   Dim intMinDiff As Integer
  4.  
  5.   intMinDiff = DateDiff("n", Me![Start], Me![End])
  6.  
  7.   If intMinDiff Mod 15 = 0 Then
  8.     Me![diffRoundUp] = intMinDiff
  9.   Else
  10.     Me![diffRoundUp] = intMinDiff + (15 - (intMinDiff Mod 15))
  11.   End If
  12. Else
  13.   Me![diffRoundUp] = Null
  14. End If
  15. End Sub
Thats fantastic. Thanks a lot for your help
Oct 2 '07 #10
FishVal
2,653 Recognized Expert Specialist
Thanks, but I want to always round up. Do you know of a variation of it to go up?
If you take a closer look to the expression you'll see that it rounds up (rounding down negative number means rounding up its absolute value).

-Int(-16/15)*15=30 for example
Oct 2 '07 #11
ADezii
8,834 Recognized Expert Expert
Thats fantastic. Thanks a lot for your help
Anytime, glad it worked out for you.
Oct 2 '07 #12
ADezii
8,834 Recognized Expert Expert
If you take a closer look to the expression you'll see that it rounds up (rounding down negative number means rounding up its absolute value).

-Int(-16/15)*15=30 for example
Interesting approach FishVal, it's almost like you have to think negatively (LOL).
Oct 2 '07 #13
FishVal
2,653 Recognized Expert Specialist
Twas brillig, and the slithy toves
Did gyre and gimble in the wabe:
All mimsy were the borogoves,
And the mome raths outgrabe.

:-P

Nothing new.
Oct 2 '07 #14

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

Similar topics

3
6716
by: Norvin Laudon | last post by:
Hi, Can somebody explain the following, from the MSDN documentation for the "System.Convert.ToInt32(double)" function <quote> Return Value value rounded to the nearest 32-bit signed...
4
7816
by: spebola | last post by:
I am using vb.net 2003 professional and I get the following results when using the round method: dim Amount as decimal = 180.255 Amount = Amount.Round(Amount, 2) Amount now contains 180.25. ...
8
2066
by: Zorpiedoman | last post by:
Howcome: Dim D as decimal = .5D msgbox d.Round(D, 0) this returns "0" Now when I went to school .5 rounds UP to 1 not DOWN to zero?????!!! Documentation says this, but what the heck are...
2
2598
by: Jiri Nemec | last post by:
Hello all, I have got one table with rounding values, table contains prices and round types. id price_from price_to rounding 1 0 1500 0.1 2 1500 ...
11
6620
by: cj | last post by:
Lets assume all calculations are done with decimal data types so things are as precise as possible. When it comes to the final rounding to cut a check to pay dividends for example in VB rounding...
18
2195
by: jdrott1 | last post by:
i'm trying to round my currency string to end in 9. it's for a pricing application. this is the function i'm using to get the item in currency: FormatCurrency(BoxCost, , , , TriState.True) if...
5
7989
by: Spoon | last post by:
Hello everyone, I don't understand how the lrint() function works. long lrint(double x); The function returns the nearest long integer to x, consistent with the current rounding mode. It...
206
13093
by: md | last post by:
Hi Does any body know, how to round a double value with a specific number of digits after the decimal points? A function like this: RoundMyDouble (double &value, short numberOfPrecisions) ...
20
4958
by: jacob navia | last post by:
Hi "How can I round a number to x decimal places" ? This question keeps appearing. I would propose the following solution #include <float.h> #include <math.h>
30
29448
by: bdsatish | last post by:
The built-in function round( ) will always "round up", that is 1.5 is rounded to 2.0 and 2.5 is rounded to 3.0. If I want to round to the nearest even, that is my_round(1.5) = 2 # As...
0
7225
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
7382
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...
1
7042
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...
0
5627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5052
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3181
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.