Wednesday, April 06, 2011

Rounding Waktu (contoh kasus dalam Ms Access)

Rounding dates and times

Note that the Date/Time data type in Access is a special kind of floating point type, where the fractional part represents the time of day. Consequently, Date/Time fields that have a time component are subject to floating point errors as well.

The function below rounds a date/time value to the specified number of seconds. For example, to round to the nearest half hour (30 * 60 seconds), use:
    =RoundTime([MyDateTimeField], 1800)

Public Function RoundTime(varTime As Variant, Optional ByVal lngSeconds As Long = 900&) As Variant
'Purpose: Round a date/time value to the nearest number of seconds
'Arguments: varTime = the date/time value
' lngSeconds = number of seconds to round to.
' e.g. 60 for nearest minute,
' 600 for nearest 10 minutes,
' 3600 for nearest hour,
' 86400 for nearest day.
'Return: Rounded date/time value, or Null if no date/time passed in.
'Note: lngSeconds must be between 1 and 86400.
' Default rounds is nearest 15 minutes.

Dim lngSecondsOffset As Long

RoundTime = Null 'Initialize to return Null.
If Not IsError(varTime) Then
If IsDate(varTime) Then
If (lngSeconds < 1&) Or (lngSeconds > 86400) Then
lngSeconds = 1&
End If
lngSecondsOffset = lngSeconds * CLng(DateDiff("s", #12:00:00 AM#, TimeValue(varTime)) / lngSeconds)
RoundTime = DateAdd("s", lngSecondsOffset, DateValue(varTime))
End If
End If
End Function

di tambil dari http://allenbrowne.com/round.html
--
Dikirim dari suwidi.or.id dengan dukungan dev-NET(system)

Pembulatan dalam Ribuan (3 digit rounding)

Ketika ada edaran dari Dirjen Bea dan Cukai untuk membulatkan pecarahn rupiah kedalam ribuan maka otomatis program yang selama ini menggunakan pembulanan terdekat (nearest) harus di hitung ulang.

(memenuhi aturan dari "Peraturan Direktur Jendral Bea Dan Cukai No P-42/BC/2008")

Berikut adalah metode yang digunakan dalam MS ACESS (rounding 3 digit)

1. Pembulatan yang medekati

1000 * Round([nilai] / 1000, 0)

2. Pembulatan ke bawah

1000 * Int([nilai] / 1000)

3. Pembulatan keatas (ini yang digunakan)

1000 * Int([nilai] / -1000)


Demikian semoga trik ini bisa membantu


--
Dikirim dari suwidi.or.id dengan dukungan dev-NET(system)