Function Ceiling หรือ Floor สำหรับ ASP
เนื่องจาก ASP Classic ไม่มี function Ceiling หรือ Floor สำหรับ การปัดเศษขึ้นลง ซึ่งถือว่ามีความจำเป็นมาก เลยเก็บมาไว้ให้ดูกันครับ
Function Ceiling(byval n)
Dim iTmp, bErr, f
on error resume next
n = cdbl(n)
if err then bErr = true
on error goto 0
if bErr then Err.Raise 5000, "Ceiling Function", _
"Input must be convertible to a sub-type of double"
f = Floor(n)
if f = n then
Ceiling = n
Exit Function
End If
Ceiling = cInt(f + 1)
End Function
Function Floor(byval n)
Dim iTmp, bErr
on error resume next
n = cdbl(n)
if err then bErr = true
on error goto 0
if bErr then Err.Raise 5000, "Floor Function", _
"Input must be convertible to a sub-type of double"
'Round() rounds up
iTmp = Round(n)
'test rounded value against the non rounded value
'if greater, subtract 1
if iTmp > n then iTmp = iTmp - 1
Floor = cInt(iTmp)
End Function




