CEIL FunctionSummaryReturns the mathematical "ceiling" of a floating-point numeric value, in effect rounding a floating-point value with a fractional part up to the next higher integer number value. Syntax
CEIL(floating-point numeric expression) Remarks and ExamplesThe CEIL function "rounds" a floating-point value up to the next higher integer value, unless the fractional part of the floating-point value is already .0. For example, CEIL(5.00001) gives 6, and CEIL(5.9) gives 6. CEIL(5.0) gives 5. The logic is the same for negative numbers. CEIL(-5.0001) gives -5. CEIL(-5.9) also gives -5, because -5 is higher on the number line than -6. The following sample program compares the effects of the INT, TRUNC, CEIL, FLOOR, and ROUND functions, all of which can be used to convert a floating-point value to an integer. 10 OPTION TABWIDTH 10 100 DIM VALUES(6) 110 VALUES(1) = 3.1 120 VALUES(2) = 3.5 130 VALUES(3) = 3.9 140 VALUES(4) = -7.1 150 VALUES(5) = -7.5 160 VALUES(6) = -7.9 200 PRINT "Function", 210 FOR X = 1 TO 6 220 PRINT VALUES(X), 230 NEXT X 240 PRINT 300 PRINT "INT", 310 FOR X = 1 TO 6 320 PRINT INT(VALUES(X)), 330 NEXT X 340 PRINT 400 PRINT "TRUNC", 410 FOR X = 1 TO 6 420 PRINT TRUNC(VALUES(X)), 430 NEXT X 440 PRINT 500 PRINT "CEIL", 510 FOR X = 1 TO 6 520 PRINT CEIL(VALUES(X)), 530 NEXT X 540 PRINT 600 PRINT "FLOOR", 610 FOR X = 1 TO 6 620 PRINT FLOOR(VALUES(X)), 630 NEXT X 640 PRINT 700 PRINT "ROUND", 710 FOR X = 1 TO 6 720 PRINT ROUND(VALUES(X)), 730 NEXT X 740 PRINT RUN Function 3.1 3.5 3.9 -7.1 -7.5 -7.9 INT 3 3 3 -7 -7 -7 TRUNC 3 3 3 -7 -7 -7 CEIL 4 4 4 -7 -7 -7 FLOOR 3 3 3 -8 -8 -8 ROUND 3 4 4 -7 -7 -8 Copyright 2006-2008, Kevin Matz, All Rights Reserved. |
|