Cobol 破折号让我感到困惑

发布于 2024-12-06 09:15:31 字数 426 浏览 1 评论 0原文

可能的重复:
cobol 与带有破折号 (-) 的图片的差异和 a 有一个 X

我正在努力掌握 Cobol,但在格式化数字时无法理解破折号。我有这个例子:

--9

我的以下说法正确吗?
第一个破折号 - 如果数字是负数,则添加破折号,否则不要。
第二个破折号 - 我对此感到困惑。开头已经有一个破折号来指定它是负数还是正数。
9 - 数字 (0-9)

举个例子就很好了。 :

谢谢

Possible Duplicate:
cobol difference with Picture having a dash (-) and a having a X

I'm tying to get to grips with Cobol and can't understand the dashes when formatting a number. I have this example:

--9

Am I correct with the following?
The first dash - If number is a negative put a dash otherwise don't.
the second dash - I'm confused with this. There is already a dash at the start to specify whether its negative or positive.
9 - Numeric digit (0-9)

An example would be good. :S

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉殇 2024-12-13 09:15:31

鉴于您的上一个问题 ,我不确定你遇到了什么问题。但让我们再试一次...

在 COBOL 中,数字显示字段可能包含各种类型的“标点符号”。这个“标点符号”是在 PICTURE 子句中定义的。您可以使用的“标点符号”类型的一些示例包括:显式小数点、加号/减号、CR/DR 指示符和千位分隔符(北美为逗号)。有一组明确定义的规则,用于确定 PICTURE 子句中可以出现什么类型的“标点符号”以及出现在何处。此链接指向图片条款 编辑解释了如何构造(或读取)任何给定的 PICTURE 子句。

您和许多其他刚接触 COBOL 的人都会遇到的一件事是,COBOL 中的数据定义指定了有关数字显示数据的两种截然不同的信息类型。一是它可以容纳的值的范围,另一个是它如何
可以显示该值范围。您的示例:PICTURE --9 告诉我有关数据项的两件事:1) 值是 -99 到 +99 范围内的整数,2) 显示此项目将占用 3 个空格。如果数字是正数,则第一个非零数字之前将出现空格。如果数字为负数,则第一个非零数字的左侧将立即出现负号。考虑以下 COBOL DISPLAY 语句:

 DISPLAY '>' DISP-NBR '<'

IF DISP-NBR 的 PICTURE 子句为:--9 这是显示各种值的方式。

  0 displays as: >  0<
 -1 displays as: > -1<
-11 displays as: >-11<
 10 displays as: > 10<

请注意,所有显示均占用 3 个字符位置。至少会显示 1 位数字(因为 PICTURE 子句中的“9”),除此之外,不显示前导零。仅当负值时才会显示减号。减号(如果显示)将位于第一个显示数字的左侧。

现在回答您的具体问题:显示数字显示数据项所需的字符位置总数由PICTURE的长度决定。您有一张 3 字符图片,因此需要 3 个字符位置。什么时候
图片中指定了一个标志,总是为其保留一个空间。这就是将整数范围限制为最多包含 2 位数字的原因。第二个减号表示“零抑制”。零抑制只是意味着不打印前导零。仅打印 1 个减号,并且它将位于第一个显示数字的左侧。

COBOL 在显示数字方面具有很大的灵活性。了解数字显示 PICTURE 子句是理解这一切如何工作的关键。

In view of your previous question, Im not sure what you are having trouble with. But lets try again...

In COBOL, numeric display fields may contain various types of "punctuation". This "punctuation" is defined in the items PICTURE clause. A few examples of the type of "punctuation" symbols you can use are: Explicit decimal points, plus/minus signs, CR/DR indicators and thousnads separators (commas in North America). There is a well defined set of rules that determine what type of "punctuation" can occur in the PICTURE clause and where. This link to PICTURE CLAUSE editing explains how to construct (or read) any given PICTURE clause.

One thing that you, and many others new to COBOL, trip up on is that a data definition in COBOL specifies two distinctly different types of information about numeric display data. One is the range of values it may hold and the other is how
that range of values may be displayed. Your example: PICTURE --9 tells me two things about the data item: 1) Values are integers in the range of -99 through to +99, and 2) Displaying this item will take 3 spaces. If the number is positive, spaces will appear before the first non zero digit. If the number is negative a minus sign will appear immediately to the left of the first non zero digit. Consider the following COBOL DISPLAY statement:

 DISPLAY '>' DISP-NBR '<'

IF DISP-NBR has a PICTURE clause of: --9 this is how various values will be displayed.

  0 displays as: >  0<
 -1 displays as: > -1<
-11 displays as: >-11<
 10 displays as: > 10<

Note that all displays take 3 character positions. At least 1 digit will always be displayed (because of the '9' in the PICTURE clause), other than that, no leading zeros are displayed. A minus sign will display only for negative values. The minus sign, if displayed will be to the immediate left of the first displayed digit.

Now to answer you specific question: The total number of character positions needed to display a numeric display data item is determined by the length of the PICTURE. You have a 3 character PICTURE so 3 character positions are needed. When
a sign is specified in the PICTURE, a space is always reserved for it. This is what limits the range of integers to those containing at most 2 digits. The second minus sign indicates 'zero supression'. Zero supression just means not printing leading zeros. Only 1 minus sign is ever printed and it will be to the immediate left of the first displayed digit.

COBOL contains a lot of flexability with respect to displaying numbers. Understanding the numeric display PICTURE clause is key to understanding how this all works.

尴尬癌患者 2024-12-13 09:15:31

来自stackoverflow:cobol-difference -带有破折号和斧头的图片

破折号表示如果你有负数,破折号将是
显示在号码旁边(左侧)。只有一个破折号
显示。如果数字为正数,则每个数字都会显示一个空格
破折号。

from stackoverflow:cobol-difference-with-picture-having-a-dash-and-a-having-a-x

The dash means that if you have a negative number, a dash will be
shown beside (at the left) of the number. Only one dash will be
displayed. If the number is positive, a space will shown for every
dashes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文