TRUNCATE Function
The TRUNCATE function trims and returns (without rounding) the number value you specify at the number of decimal points you specify.
TRUNCATE is also used to evaluate whether a specific amount or if any decimal places exist at all (See example below). The difference between the TRUNCATE function and the ROUND function is that TRUNCATE simply "cuts off" a number at a specified digit, while ROUND actually rounds a number up or down, based on where you want the number rounded.
Function name | TRUNCATE |
Usage model | TRUNCATE ( VAR, NUM ) |
Parameters | This function requires you to replace two parameters: |
VAR |
The function shortens this number value by a certain amount of places after the decimal point. |
NUM |
The function shortens VAR by this specified value. |
Result | A number value. |
Example
You can truncate a decimal number a specified number of places after a decimal point.
For example, the following script truncates the number 5.9375 to include only the first two digits after the decimal point. The truncated value is 5.93:
SET NumberVar TO TRUNCATE ( 5.9375, 2 )
In the next example, however, a Computation tests if the value of Rent Amount includes cents. The variable is then formatted to eliminate the text AND NO CENTS from being merged when the variable contains only a whole number:
IF Rent Amount = TRUNCATE( Rent Amount, 0 ) FORMAT( Rent Amount, "NINE DOLLARS" ) ELSE FORMAT( Rent Amount, "NINE DOLLARS AND TWELVE CENTS" ) END IF