When I build the following program with GnuCOBOL 3.2 on macOS and enter 10.5
, why does it print 10.0
?
program-id. foo.
data division.
working-storage section.
77 x pic 99v9.
procedure division.
accept x.
display x.
stop run.
Similarly, if I change the Picture clause to PIC 9(3)V99
and enter 458.12
, it prints 458.10
.
The picture character V
is an implied decimal point. Therefore your first example does an implicit MOVE
of 10.
The invalid .
is replaced. Similar for the longer variant.
What you can do is to ACCEPT
a bigger PIC X
field and then MOVE FUNCTION NUMVAL (INP-FLD) TO x
which then uses the implied decimal to position it correctly. This also has the benefit that you can use a sign along with the S
picture character, which in your example of a USAGE DISPLAY
variable will do an "overpunch" of a character to store negative values.