View previous topic :: View next topic
|
Author |
Message |
oerdgie
New User
Joined: 22 Nov 2007 Posts: 64 Location: Germany
|
|
|
|
Hi Folks,
how can I convert a numeric value into a packed signed decimal in REXX ?
Examples :
123 converted to '123C'x (positiv)
4456 converted to '04456D'x (negativ) |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
Add these to your collection of common procedures:
/* packed to decimal */
p2d: procedure
arg pd
Return (translate(right(C2X(pd),1),'-- ','BDACEF')||left(C2X(pd),length(C2X(pd))-1)) + 0
/* decimal to packed */
d2p: procedure
arg dec
If dec < 0 then s = 'D'; else s = 'C'
n = space(translate(dec,,'+-.')s,0)
Return X2C(right(n,length(n)+length(n)//2,'0')) |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
oerdgie wrote: |
how can I convert a numeric value into a packed signed decimal in REXX ?
Examples :
123 converted to '123C'x (positiv)
4456 converted to '04456D'x (negativ) |
4456 is positive.
Anyway, strip the sign, concatenate the number with 'C' (+) or 'D' (-) and use x2c(whatever). REXX will take care of the potential added initial zero. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Hey guys, quite a few of us are getting on in years, what's going to happen when we're gone and nobody can ever work out how to search or find a manual |
|
Back to top |
|
|
oerdgie
New User
Joined: 22 Nov 2007 Posts: 64 Location: Germany
|
|
|
|
Thanks for help !
Regards |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
expat wrote: |
Hey guys, quite a few of us are getting on in years, what's going to happen when we're gone and nobody can ever work out how to search or find a manual |
See if you can find the short story "MS Found in a Library" (not to be confused with Poe's "MS Found in a Bottle"). |
|
Back to top |
|
|
|