## Posted By

Scooter on 05/19/08

# Ceiling and Floor

/ Published in: ASP

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 Mathematics Library - Floor and Ceiling Functions    '    ' Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved.    '    ' This work is licensed under the Creative Commons Attribution License. To view    ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or    ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California    ' 94305, USA.     ' Returns the largest integer less than or equal to the specified number.    function floor(x)        dim temp         temp = Round(x)         if temp > x then            temp = temp - 1        end if         floor = temp    end function     ' Returns the smallest integer greater than or equal to the specified number.    function ceil(x)        dim temp         temp = Round(x)         if temp < x then            temp = temp + 1        end if         ceil = temp    end function%>`