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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Round a number. 1

Status
Not open for further replies.

tamer64

IS-IT--Management
Aug 27, 2007
120
US
Hello,

I need some assistance with rounding up.

I have a field in which the data type is a Number and the field size is set to double. I am look for a way round up to the nearest quarter.

Example:
1.32 round up 1.75
0.07 round up 0.25
48.54 round up 49.0
1.15 round up 1.25
2.21 round up 2.5

Thank You for your assistance.
 
How can you suggest 1.32 "round up to the nearest quarter" is 1.75 and not 1.5? Also, shouldn't 48.54 be rounded up to 48.75 and 2.21 round up to 2.25?

You could try a user-defined function like:
Code:
Public Function RoundIt(dblValue As Double, dblIncrement As Double, strUpDwn As String) As Double
    Dim intInverseIncrement As Integer
    Dim dblWorkValue As Double
    intInverseIncrement = 1 / dblIncrement
    Select Case strUpDwn
        Case "U"
            dblWorkValue = dblValue + dblIncrement
        Case "D"
            dblWorkValue = dblValue - dblIncrement
    End Select
    dblWorkValue = Int(dblWorkValue * intInverseIncrement)
    dblWorkValue = dblWorkValue / intInverseIncrement
    RoundIt = dblWorkValue
End Function

roundit(2.21,0.25,"u") = 2.25
roundit(48.54,0.25,"u") = 48.75

Duane
Hook'D on Access
MS Access MVP
 
Duane,

Thank you for assisting!

It's the way jobs are billed here. If an employee performs a job and takes him 1.21 hrs the vendor is then billed for 1.5 hrs.

I have tried to run the query Billed: RoundIt([LinkTime]) but I am receiving the following error message:

"Wrong number of arguments used with function in query expression 'RoundIt ([LinkTime])"

Any suggestions?
 
The function is designed to be accurate and flexible. You need to send in several parameters as per my two examples:

SQL:
Billed: RoundIt([LinkTime],0.25,"u")
4

As Andy and I both have pointed out, your examples seems a bit wonky.

Duane
Hook'D on Access
MS Access MVP
 
tamer64 said:
[blue] If an employee performs a job and takes him [purple]1.21 hrs[/purple] the vendor is then billed for [purple]1.5 hrs[/purple].[/blue]
There it is again ... is'nt the next highest quarter [green]1.25[/green] ... [purple]?[/purple]

See Ya . . .

Be sure to see FAQ219-2884 Worthy Reading! [thumbsup2]
Also FAQ181-2886 Worthy Reading! [thumbsup2]
 
Duane,

I got it to work!

Thanks again for your assistance!
 
If you found the help useful, use

[blue] Like this post?
Star it![/blue]


To show appreciation.
The star also shows other visitors this answer helped you.


Have fun.

---- Andy
 
tamer64 . . .

Should exact quarters roundup as well?

[blue]Your Thoughts?[/blue]

See Ya . . .

Be sure to see FAQ219-2884 Worthy Reading! [thumbsup2]
Also FAQ181-2886 Worthy Reading! [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top