CEILING vs ROUND vs TRUNC
CEILING vs ROUND vs TRUNC is a SQL function in the Numeric Functions category. Three different ways to handle decimal numbers: CEIL rounds up, ROUND to nearest, TRUNCATE chops off. The syntax is CEILING(num) / ROUND(num, decimals) / TRUNCATE(num, decimals). It accepts num. It returns rounded value. A typical example: SELECT CEILING(3.14); -- 4 (rounds up to nearest integer) SELECT CEILING(-3.14); -- -3 (rounds toward positive infinity) SELECT ROUND(3.14, 1); -- 3.1 (nearest tenth) SELECT ROUND(3.15, 1); -- 3.2 (standard rounding) SELECT TRUNCATE(3.149, 2); -- 3.14 (just chops off, no rounding) SELECT TRUNCATE(3.149, 1); -- 3.1 -- FLOOR vs CEILING: -- FLOOR: rounds toward negative infinity -- CEILING: rounds toward positive infinity SELECT FLOOR(3.14); -- 3 SELECT FLOOR(-3.14); -- -4… A close relative is ROUND(), which rounds a number to a specified number of decimal places. A close relative is ABS(), which returns the absolute (positive) value of a number.