TRUNCATE: Truncating a Number to a Given Number of Decimal Places

How to:

Given a numeric expression and an integer count, TRUNCATE returns the numeric expression truncated to that number of decimal places. If the number of decimal places is negative, it truncates to the left of the decimal point.

Syntax: How to Truncate a Number to a Given Number of Decimal Places

TRUNCATE(num_exp, count)

where:

num_exp

Numeric

Is the numeric expression to be truncated.

count

Numeric

Is the number of decimal places to which the numeric expression is to be truncated. If the number of decimal places is negative, TRUNCATE truncates to the left of the decimal point.

Example: Truncating a Number to a Given Number of Decimal Places

The following request truncates the LISTPR field to 1 decimal place and to -1 decimal places.

TABLE FILE MOVIES
PRINT LISTPR
AND  COMPUTE
TRUNCATE_PLUS1/D12.3 = TRUNCATE(LISTPR, 1);
TRUNCATE_MINUS1/D12.3 = TRUNCATE(LISTPR, -1);
BY MOVIECODE
WHERE RECORDLIMIT EQ 3
ON TABLE SET PAGE NOLEAD
ON TABLE SET STYLE *
GRID=OFF,$
ENDSTYLE
END

The output is shown in the following image.