View previous topic :: View next topic |
Author |
Message |
jctgf Beginner
Joined: 05 Nov 2006 Posts: 89 Topics: 36
|
Posted: Sun Apr 12, 2009 5:16 pm Post subject: usage of the P symbol in Cobol picture |
|
|
hi there,
I wonder if someone could provide a practical example for the P symbol in the Cobol picture definition.
That's what I've got in a test I did:
Code: |
01 w-variable pic 9(09)p comp-3.
move 123.456 to w-variable.
display 'w-var=' w-variable.
w-var= 000000056
|
I can't understand its purpose.
Thanks. |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Sun Apr 12, 2009 8:15 pm Post subject: |
|
|
jctgf,
Hmm unless I am gravely mistaken shouldn't W-variable contain 12? instead of 56? You haven't defined a decimal point so only the integer part(123) is moved to w-variable and since you have P on the right , a decimal is assumed and the actual value would be 120 as having Symbol P assumes the decimal point in the prescribed location and zero in place of the digit position specified by the symbol P.
Kolusu |
|
Back to top |
|
 |
jctgf Beginner
Joined: 05 Nov 2006 Posts: 89 Topics: 36
|
Posted: Mon Apr 13, 2009 5:52 am Post subject: |
|
|
yes, it may be 12 instead of 56.
i'm trying to guess the result i got at work, but i really don't remember.
as to the purpose, it's still a little bit blurred to me.
is the goal of the P symbol merely to replace the digit at that position for an 0?
could you provide an example of a situation in which it would be mandatory to use it, please?
thanks. |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Mon Apr 13, 2009 11:57 am Post subject: |
|
|
jctgf,
Well I don't have a practical example but I guess it can be used to calculate to the nearest integer involving decimals in a financial application.
As a simple example , an item costs $83.95 and the tax rate is 9.25% so when calculating the tax on $83.95 it would be 7.765375. Now using a P symbol they can round it down to 7.765370 or or 7.76530
or 7.7650
Kolusu |
|
Back to top |
|
 |
jctgf Beginner
Joined: 05 Nov 2006 Posts: 89 Topics: 36
|
Posted: Mon Apr 13, 2009 6:21 pm Post subject: |
|
|
thanks. |
|
Back to top |
|
 |
|
|