A numeric literal is a character string selected from the digits, the plus sign, the minus sign, and the decimal point.
The following rules govern the formation of numeric literals:
If a literal conforms to the rules for formation of a numeric literal, but is enclosed in quotation marks, it is a nonnumeric literal.
Numeric literals may also be specified using binary, octal, or hexadecimal notation. To specify a numeric literal in one of these forms, preface the number with one of the following prefixes:
For example:
Number | Binary | Octal | Hexadecimal |
---|---|---|---|
3 | B#11 | O#3 | X#3 or H#3 |
8 | B#1000 | O#10 | X#8 or H#8 |
12 | B#1100 | O#14 | X#C or H#C |
128 | B#10000000 | O#200 | X#80 or H#80 |
255 | B#11111111 | O#377 | X#FF or H#FF |
Leading zeroes after the # are ignored. For example, X#00FF and X#FF are equivalent.
The Compiler converts each numeric literal specified in this way to an unsigned long integer. In most cases, this is a 32-bit unsigned number, so the maximum value of a numeric literal that can specified with this notation is 4294967295, or (2**32) -1.
The LENGTH OF expression can be used anywhere you would use a numeric literal, except as a subscript or reference modifier. The Compiler treats this expression as if you have coded a numeric literal. The LENGTH OF expression is written as follows:
LENGTH OF data-name
data-name can be a numeric or nonnumeric literal or the name of a data item of any type. Data-name may include subscripts if it refers to a table item. The Compiler calculates the value of the LENGTH OF expression and replaces it with a numeric literal equivalent to the current number of bytes of storage used by the data item or literal referenced in LENGTH OF. For example:
77 my-item PIC x(10). 78 my-item-length value LENGTH OF my-item.
becomes:
77 my-item PIC x(10). 78 my-item-length value 10.
The LENGTH OF expression can also be used in the procedure division as demonstrated in this example:
01 my-data. 03 my-table occurs 20 times. 05 my-element-1 pic x(10). 05 my-element-2 pic 99. MOVE LENGTH OF my-element-1 TO data-size. MOVE LENGTH OF my-table TO data-size. MOVE LENGTH OF my-table(1) TO data-size.
In this example the Compiler treats the first MOVE as MOVE 10 TO data-size, the second MOVE as MOVE 240 TO data-size, and the third MOVE as MOVE 12 TO data-size.
[ + ] k.m { E } [ + ] n [ - ] { e } [ - ]
In the above:
Here are a few examples of floating-point numbers:
-12.345e12 .0123E-6 123.E1