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

rounding single or time formats

Status
Not open for further replies.

cochise

Technical User
Mar 27, 2001
171
US
Are there built in functions for rounding:

singles - the nearest 1/4
time - to the nearest 1/4 hour

 
I do not think so, however it is not complicated to write your own function to do so.

Case u need help I could be of some assistance.
 
Some assistance would be greatly appreciated
 
This function will display a number rounded to the nearest 1/4:

Function round_number(data)
dim number
number= data-int(data)

select case(number)
number = data - Int(data)

Select Case number
Case Is > 0.875: number = 1
Case Is > 0.625: number = 0.75
Case Is > 0.375: number = 0.5
Case Is > 0.125: number = 0.25
Case Else: number = 0

End Select

round_number = Int(data) + number

End Function

To the same with time build a similar function.

 
Ug. AND UgLy!.

this was answered for the Half Hour in another post. Use the example there (for the half hour) and see what is going on. From that you should be able to do the rounding a bit nore easily.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Would you point to the solution you've referenced.

Thanks
 
I couldn't find the thread, but I did find the soloution I posted. Note that this soloution was specifically intended to TRUNCATE the time to the Half-Hour increment, so some adjustments need to be made to ROUND to anything. It is only meant as an example of a way to deal with time values.

Code:
Public Function basTruncHalfHour(TimeIn As Date) As Date

    'Michael Red 12/3/01
    'Sample Usage:
    '? basTruncHalfHour(#12:17:03 AM#)
    '12:00:00 AM

    '? Format(basTruncHalfHour(#12:17:03 AM#), "h:mm")
    '0:00

    '? Format(basTruncHalfHour(#3:46:07 PM#), "h:mm")
    '15:30

    '? basTruncHalfHour(#3:46:07 PM#)
    '3:30:00 PM


    Dim MyTime As Date

    'HalfHour = (1/(24 * 60))
    Const HalfHour = 2.08333333333333E-02

    MyTime = CDbl((TimeIn * 10 ^ 5) \ (HalfHour * 10 ^ 5)) * HalfHour
    
    basTruncHalfHour = MyTime

End Function
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