32978

Decimals in COBOL

<h3>Question</h3>

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,

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.
<h3>Answer1:</h3>

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

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.

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

...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.

来源:https://stackoverflow.com/questions/61176313/decimals-in-cobol

Recommend

  • How to compress memory space of h2 database ( in-memory mode)?
  • Emulate XMP tag with script tag and allow to copy content
  • BSD md5 vs GNU md5sum output format?
  • Image path not convert to url in swift3
  • change text of corresponding label when checkbox is checked/unchecked
  • Running web application developed using .NET 4.5 on Windows Xp clients
  • Can't subscribe to Push notification
  • Python Multi-threading Help
  • How to deploy parent project packaging war in maven
  • Multiple User Types In Django
  • How to change the menu content by using DataTrigger in XAML?
  • Jenkins job DSL plugin - hidden parameter
  • Saving data from textboxes into text file
  • How to detect user changing sheet?
  • Getting a photo of a place from Google Places Api
  • Jquery Skill bar effect starts when you scroll to the section
  • Google Cloud dataflow : Read from a file with dynamic filename
  • How to split a string into a list by digits? [duplicate]
  • Creating and managing two independent random number sequences
  • Example of using Service Exists MSBuild task in Microsoft.Sdc.Tasks?
  • Connect to a local database from phpmyadmin with R
  • using maven pom while creating jar:test-jar some times it says JAR will be empty - no content was ma
  • Google Spreadsheet Script to Blink a range of Cells
  • How do I add a mouse over tooltip to an Image using .DrawImage()
  • php “page caching” solution suggestions for CMS Applications
  • Unity3d lost directional light shadows after generate assetBundle (.unity3d file)
  • Jersey serializes character value to ASCII equivalent numeric string
  • CAS 4 - Not able to retrieve the LDAP groups after successful authentication
  • Running R's aov() mixed effects model from Python using rpy2
  • What does the “id” field in an Android “Google Play Music” broadcast intent correspond to?
  • How to mutate multiple variables without repeating codes?