Page 1 of 1

Difference between 9.99 and 9v99?

Posted: Tue Jan 23, 2024 7:17 pm
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?

Re: Difference between 9.99 and 9v99?

Posted: Wed Jan 24, 2024 12:32 am
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.

Re: Difference between 9.99 and 9v99?

Posted: Thu Jan 25, 2024 4:35 pm
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?

Re: Difference between 9.99 and 9v99?

Posted: Thu Jan 25, 2024 10:45 pm
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.

Re: Difference between 9.99 and 9v99?

Posted: Fri Jan 26, 2024 4:16 am
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.