The TRUNCATE function returns expression-1 truncated to some number of places to the right or left of the decimal point.
If expression-2 is not negative, expression-1 is truncated to the expression-2 number of places to the right of the decimal point.
If expression-2 is negative, expression-1 is truncated to the absolute value of (expression-2+1) number of places to the left of the decimal point.
If the absolute value of expression-2 is larger than the number of digits to the left of the decimal point, the result is 0. For example, TRUNCATE(748.58,-4) = 0.
The data type and length attribute of the result are the same as the data type and length attribute of the first argument.
If either argument can be null, the result can be null. If either argument is null, the result is the null value.
SELECT TRUNCATE(MAX(SALARY/12, 2) FROM EMPLOYEEBecause the highest paid employee in the sample employee table earns $52750.00 per year, the example returns the value 4395.83.
SELECT TRUNCATE(873.726, 2), TRUNCATE(873.726, 1), TRUNCATE(873.726, 0), TRUNCATE(873.726, -1), TRUNCATE(873.726, -2), TRUNCATE(873.726, -3) FROM SYSIBM.SYSDUMMY1
Returns the following values respectively:
0873.720 0873.700 0873.000 0870.000 0800.000 0000.000
SELECT TRUNCATE( 3.5, 0), TRUNCATE( 3.1, 0), TRUNCATE(-3.1, 0), TRUNCATE(-3.5, 0) FROM SYSIBM.SYSDUMMY1
This example returns:
3.0 3.0 -3.0 -3.0
respectively.
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.