Saturday, May 17, 2008

Ceiling and Floor

In mathematics, there are two elementary special functions called ceiling() and floor() which allow us to round up or down, respectively, to the nearest whole number. These functions exist natively in PHP, but not in ASP. They are handy in situations where you want to force a number like 15.8 to round down to 15, but the round() function rounds it up to 16 according to the standard rules for rounding.


ASP

  1. function floor(x)
  2.     dim temp
  3.     temp = round(x)
  4.     if temp > x then
  5.         temp = temp - 1
  6.     end if
  7.     floor = temp
  8. end function
  9. function ceil(x)
  10.     dim temp
  11.     temp = round(x)
  12.     if temp < x then
  13.         temp = temp + 1
  14.     end if
  15.     ceil = temp
  16. end function

No comments: