A floating-point item is a numeric data item that allows for a very wide range of values. However, compared to other numeric
data types in COBOL, floating-point data is less accurate. Most computer languages use floating-point to represent non-integer
values. This makes floating-point a good method for sharing non-integer data with these other languages.
Floating-point data items differ in several ways from normal numeric data items:
- Floating-point items are stored in a machine-dependent format. In particular, they are stored in a format that is native to
each machine. There are many floating-point formats currently in use by different machines, so floating-point data should
not be considered portable.
- Floating-point items do not have pictures associated with them. Instead, floating-point items are either 4 or 8 bytes in size.
The size of the item determines the range of values it can hold.
- The range of values that can be stored in a floating-point item is machine-dependent.
Because floating-point items do not maintain accuracy very well, you should limit their use. Some examples where floating-point
is appropriate are:
- You need to share non-integer data with another language such as C or FORTRAN.
- You need to hold very large or very small values that exceed the usual 18 digits available in COBOL.
- You need to process existing data that contains floating-point values.