Int rounding down (calculated) whole numbers

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I have a function during which a line passes a calculation to an integer,
usually all is fine, but occasionally, where the result of the calculation is
a whole number this is also rounded down (eg 12 is rounded down to 11). Note
this does not happen for all whole numbers passed, the two examples I
currently have are 12 and 28.
I suspect the cause of the problem to be in the phasing of the code for the
calculation, perhaps someone could look-it over and make some suggestions?

Background:
A function is required to round times to the nearest x mins (this element
taken as stand-alone works with no errors yet found), however the function
also needs to allow for an off-set:
eg from 7 o'clock the times to the nearest 15 mins are 7:00; 7:15; 7:30; 7:
45; 8:00 etc.
however from 7:10 (time off set by 10 mins) times are: 7:10; 7:25; 7:40; 7:
55; 8:10 etc

My “simple” solution to this is to remove the off-set time; round the the
nearest x mins; then add back the off-set.

Code:

Public Function TimeRoundDown(dteHighTime As Date, _
Optional intNearest As Integer = 60, _
Optional intMinPast As Integer = 0)
'
' This returns the time Rounded Down to the nearest interval
' if no interval is given time is rounded to nearest hour*.
'
' * mins past is used to round to nearest mins past the hour
' eg time of 7:20, rounding nearest 15 for 10 past the hour
' rounded down time is 7:10
'
Dim intTimeBlks As Double
Dim dblStdMin As Double
Dim dblConv As Double

dblStdMin = intMinPast / (24 * 60)
dblConv = 24 * 60 / nz(intNearest, 60)

dteHighTime = dteHighTime - dblStdMin

' Next line causes error:
intTimeBlks = dteHighTime * dblConv
'
TimeRoundDown = (Int(intTimeBlks) / dblConv) + dblStdMin

End Function

Known Problem values:
3:15 to the nearest 15, off-by 15 mins problem line returns 11 not 12
7:15 to the nearest 15, off-by 15 mins problem line returns 27 not 28

Any suggestions gladly received,
Simon

Ps
Access 2007 on XP or Vista pc.

--
Message posted via http://www.accessmonster.com

.



Relevant Pages

  • Re: Dmax for nearest date
    ... No one is suggesting that you change the table, ... I'm trying to identify the nearest date to today. ... The query that the report is created from does a date calculation. ...
    (microsoft.public.access.reports)
  • Re: Re: Select a canvas line "point"
    ... After some testing I implemented a simple "nearest" calculation using ... the hypoth() function point by point, ... platforms and it is not ensured, that this binary extension is always ...
    (comp.lang.tcl)
  • Re: [VAT] Calculation of VAT at retailers
    ... >> If you do not use a retail scheme, but instead calculate VAT at line ... you must not round the VAT figure down. ... round each VAT calculation. ... that calculation includes the option to round down to nearest 0.1p. ...
    (uk.business.accountancy)
  • Re: v2.6.21.4-rt11
    ... Does this patch fix it? ... on the nearest next_balance point of all domains. ... By repeating that calculation in idle_balance, are we covering any corner case? ...
    (Linux-Kernel)
  • Return quantity outstanding
    ... In the following calculation the result returned is correct, ... quantity required to round off the result to the nearest whole number, ... Prev by Date: ...
    (microsoft.public.excel.worksheet.functions)