Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access :Rounding to the next 0,25

Status
Not open for further replies.

DJMIKEDEE

Technical User
May 17, 2002
4
0
0
DE
Dear Helper,

I am writing to you all ,because I have a major problem.

I am a Admin pay clerk who calculates Local Civilians pay. Even thou we do have a good pay system, we do have calculate some groups manually, believe me it can be a pain, so I have come up with an idea to build a database with access.

The problem I have is………..
We work on an Industrial clock I.e. weekly hours 38:30 =38, 50 /5 days= 7,7 hours a day X the monthly working days (maybe 23)=177,10
But we can only process in???.00, ???.25,???.50 and???.75

The biggest problem I find are the part timers who only work maybe 18 hours a week which brings it up to 3,6 hours a day

Can you please help me with a solution to this problem.

Looking forward to a helping answer

Mike Robbins
 
This function will round a number up or down to the nearest value that you specify.

Public Function RoundUpDown(varNumber As Variant, varDelta As Variant) As Variant
' Comments :
' Parameters: varNumber
' varDelta -
' Returns : Variant -
'*******************************************************
'Name: RoundUpDown Function
'Purpose: Round varNumber to varDelta, up or down
'Inputs: varNumber - number to round
' varDelta - rounding percision
' +varDelta - rounds up
' -varDelta - rounds down
'Output varNumber rounded up/down
********************************************************
Dim VarTemp As Variant

VarTemp = CDec(varNumber / varDelta)

If Int(VarTemp) = VarTemp Then
RoundUpDown = varNumber
Else
RoundUpDown = Int(((varNumber + (2 * varDelta)) / varDelta) - 1) * varDelta
End If

End Function
----------------------------------------------------------

Examples: RoundUpDown(5.12,0.25) = 5.25

RoundUpDown(5.12,-0.25) = 5.00

RoundUpDown(5.12,0.5) = 5.5

RoundUpDown(5.12,-0.5) = 5.00

The first example should work in your case.

Dermot
 
Note: this has not been extensively, particularly for non-default # of digits to round to.

Code:
Public Function basSelRnd(AmtIn As Double, _
                          AmtRnd As Single, _
                          Optional NDigits As Integer = 2) As Double

    'Michael Red 5/19/2002 To Round [AmtIn] to the [AmtRnd]
    'to the SPECIFIED number of decimal Digits (default to 2 for "Currency")
    'Including Sign Considerations for both [AmtIn] and [AmtRnd]

    Dim ModRmdr As Single
    Dim MyIn As Long
    Dim MyRmdr As Long
    Dim SgnIn As Integer
    Dim SgnRmdr As Integer
    Dim tmpRtn As Double

    SgnIn = Sgn(AmtIn)
    SgnRmdr = Sgn(AmtRnd)
    MyIn = Abs(AmtIn * 10 ^ NDigits)
    MyRmdr = Abs(AmtRnd * 10 ^ NDigits)

    ModRmdr = MyIn Mod MyRmdr

    Select Case ModRmdr
        Case Is = 0
            tmpRtn = AmtIn
            basSelRnd = tmpRtn
        Case Is > 0
            Select Case (SgnIn = SgnRmdr)
                Case True
                    tmpRtn = (MyIn - ModRmdr + MyRmdr) / 10 ^ NDigits
                    basSelRnd = SgnIn * tmpRtn
                Case Is = False
                    tmpRtn = SgnIn * (MyIn - ModRmdr) / 10 ^ NDigits
                    basSelRnd = tmpRtn
            End Select
    End Select

End Function
MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Thank you for your help......however I do have 1 more little prob. The Module you have gave me works fine in the debug window.........you see all my data input is like this"38,5" with a comma,your module only works with a dot 38.5, so how do I change that??


DJMIKEDEE
 
For my contribution, you would need to understand (and PROPERLY SET) the international settings, which I do NOT -having never worked with them.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top