SQL FLOOR scalar function in DB2 for i SQL

SQL FLOOR scalar function in DB2 for i SQL
SQL FLOOR scalar function in DB2 for i SQL, SQL function, scalar function, sql, ibmi, sql db2
SQL FLOOR scalar function in DB2 for i SQL

FLOOR

FLOOR function is also called as greatest integer function and returns the largest integer less than or equal to the passed argument.

Syntax

FLOOR(expression)

where, expression is any numeric expression. The result can be null if the argument can be null. The result of the function has the same data type and length attribute as the argument except that the scale is 0 when the argument is DECIMAL. For example, an argument with a data type of DECIMAL(6,6) returns DECIMAL(6,0).

Example #1: Use floor function on positive number

select FLOOR(4.9), FLOOR(5.1), FLOOR(6), FLOOR(0), FLOOR(.9) from sysibm.sysdummy1

Output:

FLOOR ( 4.9 )  FLOOR ( 5.1 )    FLOOR ( 6 )     FLOOR ( 0 )   FLOOR ( .9 )
       4              5                   6               0         0     

Example #2: Use floor function on negative number

SELECT FLOOR(-4.9), FLOOR(-5.1), FLOOR(-6), FLOOR(-1.5), FLOOR(-.9)
FROM sysibm.sysdummy1                                              

Output:

FLOOR ( - 4.9 )  FLOOR ( - 5.1 )  FLOOR ( - 6 )   FLOOR ( - 1.5 )  FLOOR ( - .9 )
        5-               6-                   6-          2-              1-     

Post a Comment

© AS400 and SQL Tricks. All rights reserved. Developed by Jago Desain