Developer Guide and Reference

ID 767251
Date 10/31/2024
Public
Document Table of Contents

Rounding Specifier (ROUND=)

The rounding mode specifier temporarily changes the rounding mode set when the file was opened for formatted I/O. It is allowed in formatted input and output statements. It takes the following form:

ROUND=c-expr

c-expr

Is a scalar default character expression that evaluates to 'UP', 'DOWN', 'ZERO', 'NEAREST', 'COMPATIBLE', or 'PROCESSOR_DEFINED'.

Trailing blanks in the expression are ignored. The values specified are without regard to case.

If ROUND= does not appear, the rounding mode is unchanged. If ROUND= appears, a namelist or a format specifier must also appear in the I/O control list.

The input/output rounding mode tells the runtime library how to convert between the decimal value that appears in a formatted file and the internal machine representation of that value, which may not be exact.

A rounding mode of 'DOWN' says that the converted value will be the largest representable value that is less than or equal to the original value. A rounding mode of 'UP' says that the converted value will be the smallest representable value that is greater or equal to the original value.

A rounding mode of 'NEAREST' says that the converted value will be the closer of the two nearest representable values if one is closer than the other; otherwise, the processor picks one. A rounding mode of 'ZERO', says that the converted value will be the closest value to the original value and no greater in magnitude than the original value. A rounding mode of 'COMPATIBLE' says that the converted value will be the closer of the two nearest representable values, or the value away from zero if halfway between them.

When the rounding mode is 'PROCESSOR_DEFINED', rounding is a processor-dependent default mode. This default mode may or may not correspond to one of the other rounding modes. For ifx, this mode corresponds to 'NEAREST'.

If the RU, RD, RZ, RN, RC, or RP edit descriptors are specified in the format of a data transfer statement, they supersede the rounding mode set by a ROUND= specifier in the I/O control list or when the file was opened.

See Also