Gnucobol用小数点读取数字 [英] Gnucobol read number with decimal point with
问题描述
我正在学习COBOL。我有一个带有数字字段的文本文件,其中包含一个小数点。我已将该字段定义为PIC 9(5)V99。当读取记录并将字段作为小数点时,我得到的错误不是数字:'。00'。但是,如果我从该记录中的字段中删除小数点,则没有错误。我没有选择在该字段中请求没有小数点的文件。
我尝试了什么:
我尝试使用PIC 9(5).99。但后来我得到编译错误
字段不是数值
这不是问题使用Microfocus cobol。
将变量类型声明为PIC 9(5).99似乎完全合法 - 为什么编译器会标记错误!
但如果你有
myvar pic 9(5)V99
'V'只是一个隐含的小数点 - 变量myvar只能保存数字。
编码:将147.25移动到myvar - 这会将myvar设置为0014725,如果你把它写入文本文件,内容将是0014725而不是147.25。
我可以建议一个非常难的解决方案,但它可能(大部分都会)工作。
in
数据部门。
工作存储部分。
01文件缓冲区pic x(8)正确对齐。
01 r-file-buffer重新定义文件缓冲区。
10 f-int-part pic 9(5)。
10填充图片x
10 f-fract-part pic 99.
01 numvar pic 9(5)V99。
01 r-numvar重新定义numvar。
10 numvar-int pic 9(5)。
10 numvar-fract pic 99.
< br $>
程序部门。
将myfile读入文件缓冲区。
将f-int-part移动到numvar-int。
将f-fract-part移动到numvar-fract。
自从我在COBOL中做了任何事以来已经20多年了。
I'm learning COBOL. I have a text file with a numeric field that has a decimal point in it. I have defined the field as PIC 9(5)V99. When a record is read and the field as a decimal point it I get this error not numeric: '.00 '. But if I remove the decimal point from the field in that record, there is not an error. I don't have the option to request a file without the decimal point in that field.
What I have tried:
I tried using PIC 9(5).99. But then I get the compiler error
field is not a numeric value
This is not a problem using Microfocus cobol.
Declaring your variable type as PIC 9(5).99 seems perfectly legal - why should the compiler flag an error!
But if you had
myvar pic 9(5)V99
the 'V' is only an implied decimal point - variable myvar can hold only digits.
Coding: move 147.25 to myvar - this will set myvar to 0014725 and if you wrote this to a text file the contents would be 0014725 and not 147.25.
I can suggest a VERY UGLY solution but it may (mostly will) work.
in
data division.
working-storage section.
01 file-buffer pic x(8) justified right.
01 r-file-buffer redefines file-buffer.
10 f-int-part pic 9(5).
10 filler pic x
10 f-fract-part pic 99.
01 numvar pic 9(5)V99.
01 r-numvar redefines numvar.
10 numvar-int pic 9(5).
10 numvar-fract pic 99.
procedure division.
read myfile into file-buffer.
move f-int-part to numvar-int.
move f-fract-part to numvar-fract.
It's 20+ years since I did anything in COBOL.
这篇关于Gnucobol用小数点读取数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!