TRUNCATE function

Truncates a decimal expression to a specified number of decimal places, returning a decimal value.

Syntax

TRUNCATE ( expression , decimal-places )
expression

A decimal expression that you want to truncate.

decimal-places

A non-negative integer expression that indicates the number of decimal places for a truncated expression.

Example

This procedure doubles each Customer's CreditLimit and then truncates that value before rounding it to the nearest $1000:

r-trunc.p

FOR EACH Customer:
  FORM Customer.CustNum Customer.Name Customer.CreditLimit
    new-max LIKE Customer.CreditLimit LABEL "New Credit limit".
  DISPLAY Customer.CustNum Customer.Name Customer.CreditLimit.
  Customer.CreditLimit = 
    TRUNCATE((Customer.CreditLimit * 2) / 1000 ,0) * 1000.
  IF Customer.CreditLimit < 15000 THEN 
    Customer.CreditLimit = 15000.
  DISPLAY Customer.CreditLimit @ new-max.
END.

Notes

You can use the TRUNCATE function to treat division as integer division. For example, i = TRUNCATE (x / y, 0).

See also

ROUND function