DEC( ) function

Returns a value, or the result of a numeric expression, with the specified number of decimal places.

Syntax

DEC(number, decimals)

Parameters

Name Type Description
number numeric

The value or result to adjust the number of decimal places for.

  • integers decimal places are added to the end of number as trailing zeros.
  • fractional numbers If the number of decimal places is reduced, number is rounded, not truncated. If the number of decimal places is increased, trailing zeros are added to the end of number.
decimals numeric

The number of decimal places to use in the return value.

Note

You cannot use DEC( ) to increase the decimal precision of results.

For information about how to increase decimal precision, see Controlling rounding and decimal precision in numeric expressions.

Output

Numeric.

Examples

Basic examples

Returns 7.00:

DEC(7, 2)

Returns 7.565: 

DEC(7.5647, 3)

Returns 7.56470: 

DEC(7.5647, 5)

Advanced examples

Calculating daily interest

Calculates the daily interest to six decimal places for a field called Annual_rate:

DEC(Annual_rate, 6) / 365

Remarks

When to use DEC( )

Use this function to adjust the number of decimal places in a field, or when you want to round a value or a result to a specified number of decimal places.

DEC( ) cannot reverse fixed-point rounding

You cannot use the DEC( ) function to reverse the standard rounding that fixed-point arithmetic performs in numeric expressions.

Example

Consider the following series of expressions in Analytics:

1.1 * 1.1 = 1.2
1.1 * 1.10 = 1.21
DEC(1.1 * 1.1, 2) = 1.20

Fixed-point rounding means that the result of 1.1 * 1.1 is 1.2, not 1.21, which is the unrounded result. Using DEC( ) to specify a two-decimal-place result does not create two-decimal-place precision. Instead, it adds a trailing zero to create the specified number of decimal places, without increasing precision.

For information about how to increase decimal precision, see Controlling rounding and decimal precision in numeric expressions.

Related functions

If you want to round a value to the nearest whole number, use the ROUND( ) function.

ACL Scripting Guide 14.1