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

Rounding currency question

Status
Not open for further replies.

Artlan

Programmer
May 24, 2001
6
US
Hello

I’m trying to round those prices as follow $15.23 to 15;
15.25 to 15.50; 15.74 to 15.50; and 15.75 to 16. inside the query...



Any thoughts???

Thanks,
Arthur
 
You could use the following function:
Code:
Public Function RoundToQtr(RndNumber As Double)
    Dim Cents As Double
    Dim RndCents As Double
      
    Cents = CInt(Right(CStr(RndNumber), 2)) / 100
   
    If Cents >= 0 And Cents < 0.25 Then
        RndCents = 0
    ElseIf Cents >= 0.25 And Cents < 0.5 Then
        RndCents = 0.25
    ElseIf Cents >= 0.5 And Cents < 0.74 Then
        RndCents = 0.5
    Else
        RndCents = 0.75
    End If
   
    RndNumber = (RndNumber - Cents) + RndCents
   
End Function

And then justcall it in your query:

SELECT RoundToQtr(MyTable.MyNumber)
FROM MyTable; Terry
**************************
* General Disclaimor - Please read *
**************************
Please make sure your post is in the CORRECT forum, has a descriptive title, gives as much detail to the problem as possible, and has examples of expected results. This will enable me and others to help you faster...
 
You can try the following expression:

Int((Price + 0.25)* 2)/2

Danny
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top