Difference between 9.99 and 9v99?

Time Sharing Option, Interactive System Productivity Facility and REstructured eXtended eXecutor

Moderator: mickeydusaor

Post Reply
GhuGhu
New Member
Posts: 5
Joined: Tue Dec 22, 2015 10:12 pm

Difference between 9.99 and 9v99?

Post by GhuGhu »

Hi,

Can someone explain? Difference between 9.99 and 9v99 ?

What is main use of using V in the place of decimal point, is this just to reduce memory?
User avatar
zum13
Registered Member
Posts: 89
Joined: Thu May 04, 2023 12:58 am

Re: Difference between 9.99 and 9v99?

Post by zum13 »

Hello.

Numbers stored in packed decimal representation usually have to be defined with an implied decimal point because the packed format has no way of specifying a decimal point; there are only the individual digits and the sign.

For example, the number "+100.23" as a four byte packed field would be stored as X"0010023C". Without an implied decimal specification, if you tried to move that value to a "PIC 9(7).99" field, you'd get 10023.00, not 100.23. Your source field would need to be defined as "PIC 9(5)V99" to tell the compiler that there is a decimal point and where it belongs.

That said, you can use it in display format numbers to reduce the space requirement, but I've not seen it used like that very often.
User avatar
Oghuzacult
New Member
Posts: 1
Joined: Wed Jan 24, 2024 10:10 pm
Contact:

Re: Difference between 9.99 and 9v99?

Post by Oghuzacult »

How does the use of 'V' in the place of a decimal point impact the representation of numbers in packed decimal format, and why is it essential in scenarios where there is no explicit specification for a decimal point?
:)
User avatar
zum13
Registered Member
Posts: 89
Joined: Thu May 04, 2023 12:58 am

Re: Difference between 9.99 and 9v99?

Post by zum13 »

The only components found in packed decimal are the digits themselves and the sign. The "V" is a direction to the compiler which tells it where you want it to assume the decimal point is. It doesn't affect the stored data in the slightest.

If you don't specify it where it is needed, then your numbers with decimal places are treated as being magnitudes of 10 out. For example, if you run this:

Code: Select all

       WORKING-STORAGE SECTION. 
                                                                       
       01  WA-NUMBER-NO-DECIMAL        PIC S9(7)  COMP-3 VALUE 10023. 
       01  WA-NUMBER-DECIMAL           REDEFINES  WA-NUMBER-NO-DECIMAL 
                                       PIC S9(5)V99 COMP-3. 
       01  WA-NUMBER-FORMATTED         PIC -9(7).99. 
                                                                       
       PROCEDURE DIVISION. 
                                                                       
       A100-MAIN SECTION. 
                                                                       
           MOVE WA-NUMBER-NO-DECIMAL TO WA-NUMBER-FORMATTED 
           DISPLAY WA-NUMBER-FORMATTED 
                                                                       
           MOVE WA-NUMBER-DECIMAL TO WA-NUMBER-FORMATTED 
           DISPLAY WA-NUMBER-FORMATTED 
           . 
       A100-EXIT. 
           GOBACK. 
you get as output:

Code: Select all

 0010023.00
 0000100.23
The underlying data has not changed, but the two results are different because the redefinition has an implied decimal specified.
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1896
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Difference between 9.99 and 9v99?

Post by Robert Sample »

One place it can make a difference is in handling numeric data. A PICTURE with a decimal point is an edited-numeric variable, and edited-numeric values are NOT numeric. An IF NUMERIC test will fail. Reducing memory has NEVER, as far as I know, been a consideration for the V in a PICTURE.
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “TSO, ISPF & REXX (Do you still do CLIST?!).”