FIX function

Syntax

FIX (number [ ,precision [ ,mode ] ] )

Description

Use the FIX function to convert a numeric value to a floating-point number with a specified precision. FIX lets you control the accuracy of computation by eliminating excess or unreliable data from numeric results. For example, a bank application that computes the interest accrual for customer accounts does not need to deal with credits expressed in fractions of cents. An engineering application needs to throw away digits that are beyond the accepted reliability of computations.

number is an expression that evaluates to the numeric value to be converted.

precision is an expression that evaluates to the number of digits of precision in the floating-point number. If you do not specify precision, the precision specified by the PRECISION statement is used. The default precision is 4.

mode is a flag that specifies how excess digits are handled. If mode is either 0 or not specified, excess digits are rounded off. If mode is anything other than 0, excess digits are truncated.

If number evaluates to the null value, null is returned.

Examples

The following example calculates a value to the default precision of 4:

REAL.VALUE = 37.73629273
PRINT FIX (REAL.VALUE)

This is the program output:

37.7363

The next example calculates the same value to two digits of precision. The first result is rounded off, the second is truncated:

PRINT FIX (REAL.VALUE, 2)
PRINT FIX (REAL.VALUE, 2, 1)

This is the program output:

37.74
37.73