I have an InFile.dat
containing some integer values which I store in a record in SomeFile.cob
. When I add it to the OutFile.dat
I cannot get the integers to convert to floats.
FILE-SECTION.
*> In File:
01 someInt PIC 9. *> eg. 3
*> Out File:
01 PrintLine PIC X(75). *> for writing data to a line
WORKING-STORAGE SECTION.
01 someFloat PIC 9V99.
PROCEDURE DIVISION.
COMPUTE someFloat = someInt / 1
DISPLAY someFloat *> displays 3.00 (good)
WRITE PrintLine FROM someFloat *> stored as 300 (not good)
How can I store it in the out file as a float?
PIC 9V99
is not a floating point but a fixed-point integer value, that has a guaranteed precision.
It does not store the decimal point "in memory" so it isn't part of your outputfile, which is good (the v
is the implied decimal point which is only in effect on run-time depending on the field definition).
To output this you may use an edited field which is explicit for output (nothing you should do any calculation on):
01 someFixedPoint PIC 9V99.
01 someEdited PIC 9.99. *> use "," when DECIMAL-POINT IS COMMA
MOVE someFixedPoint TO someEdited
WRITE PrintLine FROM someEdited