The fixed-point (or F) format item describes the character representation of a real fixed-point decimal arithmetic value.
|
On input, either the data value in the data stream is an optionally signed real decimal fixed-point constant located anywhere within the specified field or the CONVERSION condition is raised. Blanks can appear before and after the data value in the field and are ignored. If the entire field is blank, it is interpreted as zero.
If no scaling-factor is specified and no decimal point appears in the field, the expression for fractional-digits specifies the number of digits in the data value to the right of the assumed decimal point. If a decimal point does appear in the data value, it overrides the expression for fractional-digits.
If a scaling-factor is specified, it effectively multiplies the data value in the data stream by 10 raised to the integer value (p) of the scaling-factor. Thus, if p is positive, the data value is treated as though the decimal point appeared p places to the right of its given position. If p is negative, the data value is treated as though the decimal point appeared p places to the left of its given position. The given position of the decimal point is that indicated either by an actual point, if it appears, or by the expression for fractional-digits, in the absence of an actual point.
If the field-width is 0, there is no assignment to the data-list item.
On output, the data-list item is converted, if necessary, to fixed-point. Floating point data converts to FIXED DECIMAL (N,q) where q is the fractional-digits specified. The data value in the stream is the character representation of a real decimal fixed-point number, rounded if necessary, and right-adjusted in the specified field.
The conversion from decimal fixed-point type to character type is performed according to the normal rules for conversion. Extra characters can appear as blanks preceding the number in the converted string. And, since leading zeros are converted to blanks (except for a 0 immediately to the left of the point), additional blanks can precede the number. If a decimal point or a minus sign appears, either will cause one leading blank to be replaced.
If only the field-width is specified, only the integer portion of the number is written; no decimal point appears.
If both the field-width and fractional-digits are specified, both the integer and fractional portions of the number are written. If the value (d) of fractional-digits is greater than 0, a decimal point is inserted before the rightmost d digits. Trailing zeros are supplied when fractional-digits is less than d (the value d must be less than field-width). If the absolute value of the item is less than 1, a 0 precedes the decimal point. Suppression of leading zeros is applied to all digit positions (except the first) to the left of the decimal point.
The rounding of the data value is as follows: if truncation causes a digit to be lost from the right, and this digit is greater than or equal to 5, 1 is added to the digit to the left of the truncated digit.
On output, if the data-list item is less than 0, a minus sign is prefixed to the character representation; if it is greater than or equal to 0, no sign appears. Therefore, for negative values, the field-width might need to include provision for the sign, a decimal point, and a 0 before the point.
If the field-width is such that any character is lost, the SIZE condition is raised.
In the example:
declare Total fixed(4,2); put edit (Total) (F(6,2));
The PUT statement specifies that the value of Total is converted to the character representation of a fixed-point number and written into the output file SYSPRINT. A decimal point is inserted before the last two numeric characters, and the number is right-adjusted in a field of six characters. Leading zeros are changed to blanks (except for a zero immediately to the left of the point), and, if necessary, a minus sign is placed to the left of the first numeric character.