View previous topic :: View next topic
|
Author |
Message |
neelesht
New User
Joined: 24 Jul 2006 Posts: 99 Location: Los Angeles
|
|
|
|
All
I have a below requirement.
I have a variable defined as
WS-WORKING-STORAGE PIC S9(11)V99
SIGN IS LEADING SEPARATE
VALUE ZEROS.
When its zeroes it should be displayed as +0.00
when its +00000000001.23, it should be displayed as +1.23
and when its when its -00000000021.89, it should be displayed as -21.89
What is the function which I can use ?
Thanks for the help. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Have you tried anything so far yourself? Read up in the manual on the PICTURE clause as it relates to edited numerics and it should provide for whatever format you want the output to be. The "leading sign" shouldn't matter at all in your current picture, the compiler will handle that.
If you don't get it after looking at the manual, let us know what problem you still have. |
|
Back to top |
|
|
neelesht
New User
Joined: 24 Jul 2006 Posts: 99 Location: Los Angeles
|
|
|
|
Bill,
Thnx for the reply. I know ZZZZ will serve the purpose but I was not sure about the sign.
I even achieved the result by coding and it was working fine but I would prefer if COBOL does it on its own and not my logic which may affect the performance.
Since you said compiler will handle the sing, let me try with ZZZZ and check. I dont have Mainframe access right now, will try it in couple of hours and let you know.
Thanks |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
The Cobol manuals are a few clicks away with the Manuals link at the top of this page.
The Z's will zero supress. If you want a leading "floating" sign, which you seem to from your example, you can replace the Zs with + or - (- if you only want the sign for negative values, + if you want for all values). I don't know if you want commas for readability, those can be included as well.
Code: |
PIC +++,+++.+++.++9.99.
PIC +(11)9.99 |
Just not that you need one more leading printable character than your picture excluding any other editing, because the sign will take up a position (even if not printed, in the case of a - picture character).
It is well-worth looking at all the editing available through the Cobol picture clause. |
|
Back to top |
|
|
Kiran Gadgi Currently Banned New User
Joined: 04 Dec 2011 Posts: 3 Location: India
|
|
|
|
I tried with the above code its working. Follow our Sr words |
|
Back to top |
|
|
neelesht
New User
Joined: 24 Jul 2006 Posts: 99 Location: Los Angeles
|
|
|
|
Thanks Bill, yes it worked although I had to do some modifications but it surely worked fine.
Thanks alot. |
|
Back to top |
|
|
|