Previous Topic Next topic Print topic


Numeric Literals

Numeric literals can be either fixed-point or floating-point numbers.

Fixed-Point Numeric Literals

A numeric literal is a character-string whose characters are selected from the digits 0 through 9, the plus sign, the minus sign, and the decimal point. This implementation allows for numeric literals of 1 to 18 digits in length. The rules for the formation of numeric literals are as follows:

  • A literal must contain at least one digit.
  • A literal must not contain more than one sign character. If a sign is used, it must appear as the leftmost character of the literal. If the literal is unsigned, the literal is positive.
  • A literal must not contain more than one decimal point. The decimal point is treated as an assumed decimal point, and can appear anywhere within the literal except as the rightmost character. If the literal contains no decimal point, the literal is an integer.
  • The value of a numeric literal is the algebraic quantity represented by the characters in the numeric literal. Every numeric literal is category numeric. (See the topic The PICTURE Clause.)

If a literal conforms to the rules for the formation of numeric literals, but is enclosed in quotation marks, it is a nonnumeric literal and is treated as such by your COBOL system.

The size of a numeric literal in standard data format characters is equal to the number of digits specified by the user.

MF In addition, hexadecimal binary values can be attributed to numeric literals by expressing literals as:
H"nn"
where each n is a hexadecimal digit in the set 0-9 A-F; nn can be repeated up to 8 times, but the number of hexadecimal digits must be even.

Floating-Point Numeric Literals

OSVSVSC2MF 

A floating-point literal is written in the form:


*

If you omit a sign, the system assumes a positive number.

The significand can contain between 1 and 16 digits. A decimal point must be included in the significand.

The exponent is represented by an E followed by an optional sign and one or two digits.

The magnitude of a floating-point literal value must fall between 0.54E-78 and 0.72E+76. For values outside this range, an error message is produced and the value is replaced by 0 or 0.72E+76 respectively. You must not use a floating-point literal when an integer literal is required.

Previous Topic Next topic Print topic