WP Remix
Nop Pinyowanichaka | ก้าวสั้นๆ ในวันเบาๆ ของผม
27
Mar

เนื่องจาก ASP Classic ไม่มี function Ceiling หรือ Floor สำหรับ การปัดเศษขึ้นลง ซึ่งถือว่ามีความจำเป็นมาก เลยเก็บมาไว้ให้ดูกันครับ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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

เรื่องอื่นๆ ที่น่าสนใจ

Category : ASP

No comments yet.

เม้นท์กันซะหน่อย