小数位数 [英] Decimals in COBOL

查看:136
本文介绍了小数位数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是COBOL的新手.我正在关注Micro Focus随附的教程,但似乎无法使示例正常工作.我正在尝试打印-123.45,并且不断收到以下消息,

I'm very new to COBOL. I'm following the tutorials that came with Micro Focus and I can't seem to get the example to work right. I'm trying to print -123.45 and I keep getting the following,

我在此处查找了许多帖子,但它们没有解决我的问题.我在 Eclipse 中使用Micro Focus的Visual COBOL.这是我的代码,

I looked up a number of posts on here and they don't address my problem. I'm using Micro Focus' Visual COBOL in Eclipse. Here's my code,

   program-id. tictac as "tictac".

   environment division.
   configuration section.

   data division.
   working-storage section.

    01 WS-NUM3 PIC S9(3)V9(2) VALUE -123.45.


   procedure division.
       Display WS-NUM3.
       goback.

   end program tictac.

推荐答案

您的picture子句中的V隐含的小数点.我想您想要一个带有PIC -999.99的字段,其中.显式小数点,用于它的picture子句.

The V in your picture clause is an implied decimal point. I think you want a field with PIC -999.99, where the . is an explicit decimal point, for its picture clause.

您可能会认为这是因为COBOL在变量的定义方式和显示方式之间进行了区分.类似于printf中的格式字符串,只是指定如何显示变量,而不是如何定义变量.尽管在这两种情况下,定义及其显示方式都必须在一定程度上匹配.

You might think of this as COBOL making a distinction between how a variable is defined and how it is shown. Sort of like a format string in printf is just specifying how to show a variable, not how it is defined. Though in both cases the definition and how it is shown have to match up to a certain extent.

为数字字段选择正确的picture子句很重要;如果您要进行计算,可能会对性能产生重大影响.

Choosing the right picture clause for a numeric field is important; if you're doing calculations it can have a significant performance impact.

因此,通常有一个带有定义的字段,例如...

So it's common to have a field with a definition such as...

PIC 9(4)V99 COMP-3

...以及用于输出目的的相应字段,例如...

...and a corresponding field for output purposes such as...

PIC ZZZ9.99

...以便可以在第一个上进行计算,并且在显示该字段是必要的时,可以使用MOVE语句将第一个的内容复制到第二个.

...so that computations can be done on the first, and when displaying the field is necessary one uses a MOVE statement to copy the contents of the first to the second.

这篇关于小数位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆