All pastes #209202 Raw Edit

Miscellany

public text v1 · immutable
#209202 ·published 2006-10-19 01:50 UTC
rendered paste body
	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

	function ceil(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
			ceil = n
		else
			ceil = cInt(f + 1)
		end if
	end function