Difference between 9.99 and 9v99?
Moderator: mickeydusaor
Difference between 9.99 and 9v99?
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?
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?
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.
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.
- Oghuzacult
- New Member
- Posts: 1
- Joined: Wed Jan 24, 2024 10:10 pm
- Contact:
Re: Difference between 9.99 and 9v99?
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?
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:
you get as output:
The underlying data has not changed, but the two results are different because the redefinition has an implied decimal specified.
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.
Code: Select all
0010023.00
0000100.23
- Robert Sample
- Global Moderator
- Posts: 1903
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: Difference between 9.99 and 9v99?
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.
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