Looking for function or technique

  • Follow


Is there a way of getting REXX to display a number like 123456789 as 
123,456,789?  I'm done some google searches and so far I've come up 
empty.  I would've SWORN there was a built-in method in REXX, but I 
can't seem to find it.

-- 
Jaime A. Cruz
President
Nassau Wings Motorcycle Club
http://www.nassauwings.org/
Member-at-Large
AMA District 34
http://www.AMADistrict34.com/
Pop's Run
http://www.popsrun.org/
0
Reply Cruz 6/11/2007 2:43:32 AM

In article <oF2bi.3210$c45.842@trndny06>, Cruz, Jaime <Spammers@Bite.Me> wrote:
% Is there a way of getting REXX to display a number like 123456789 as 
% 123,456,789?  I'm done some google searches and so far I've come up 

There's always a way

 commify: procedure
   s = reverse(arg(1))
   t = ''
   do while s <> ''
     parse var s ts +3 s
     t = t','ts
     end
   parse var t +1 t
   return reverse(t)

% empty.  I would've SWORN there was a built-in method in REXX, but I 
% can't seem to find it.

I seem to recall seeing a clever way to do this using translate().
-- 

Patrick TJ McPhee
North York  Canada
ptjm@interlog.com
0
Reply ptjm 6/11/2007 3:04:00 AM


In article <136pet08i4ko052@corp.supernews.com>,
ptjm@interlog.com (Patrick TJ McPhee) wrote:
>
>I seem to recall seeing a clever way to do this using translate().

You can reorder characters with translate(), but not insert characters as
far as I know. For example, to reorder a mm/dd/yy date to yy/mm/dd:

mm_dd_yy = '06/11/07'
yy_mm_dd = translate('78612345', mm_dd_yy, '12345678')

-- 
Don Hills    (dmhills at attglobaldotnet)     Wellington, New Zealand
"New interface closely resembles Presentation Manager,
 preparing you for the wonders of OS/2!"
    -- Advertisement on the box for Microsoft Windows 2.11 for 286
0
Reply black 6/11/2007 4:18:19 AM

| Cruz, Jaime wrote:
| Is there a way of getting REXX to display a number like 123456789 as
| 123,456,789?  I'm done some google searches and so far I've come up
| empty.  I would've SWORN there was a built-in method in REXX, but I
| can't seem to find it.

Below is a general purpose routine to add commas to any
form of REXX number, including those in scientific
notation, fractions, numbers with a leading sign,
leading/trailing/imbedded blanks, numbers with
leading/trailing currenty sign(s), etc.   Other than the
insertions, the format of the number isn't compromised.

Provision is also included to specify what character
is to be used for the insertion (default is the comma),
what size period to use (default is three characters),
and the number of insertions may also be limited.

Any size number can be processed, no matter what the
setting of NUMERIC DIGITS.

It's not a small routine, but it does what it's
supposed to.

=========================================================
comma: procedure; parse arg _,c,s,t; c=pickblank(c,",")
if \isint(s) | s<1 then s=3; n=_'.9'; #=123456789; k=0
if \isint(t) then t=9999999
  do j=verify(n,#'0',,verify(n,#"0.",'M'))-s-1 to ,
       verify(n,#,"M") by -s while k<t
  _=insert(c,_,j); k=k+1
  end
return _

isint: return datatype(arg(1),'W')

pickblank: procedure; parse arg x,y; arg xu
if xu=='BLANK' then return ' '; return word(x y,1)
=========================================================


say comma('$123456.70')            ====> $123,456.90
say comma(1234567.00e+01')         ====> 1,234,567.00e+01
say comma(+6789)                   ====> +6,789
say comma(123678,'.')              ====> 123.678
say comma(123456789012,'blank',5)  ====> 12 34567 89012

________________________________________________Gerard S.

 


0
Reply Gerard 6/11/2007 5:10:33 AM

> Is there a way of getting REXX to display a number like 123456789 as 
> 123,456,789?  I'm done some google searches and so far I've come up 
> empty.  I would've SWORN there was a built-in method in REXX, but I 
> can't seem to find it.

I couldn't think of a clever way to do it; I wrote this version a couple 
of days ago:

Number: Procedure
N = reverse(arg(1))
If length(n) > 3 then Do I = 3 to length(n) by 4
   N = insert(',',N,i)
   End
Return reverse(n)

-- 
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
0
Reply Steve 6/11/2007 6:19:23 AM

In <oF2bi.3210$c45.842@trndny06>, on 06/11/2007
   at 02:43 AM, "Cruz, Jaime" <Spammers@Bite.Me> said:

>Is there a way of getting REXX to display a number like 123456789 as 
>123,456,789?

I'm not aware of any clean way to do it, but there are simple hacks
involving reverse and translate.

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamtrap@library.lspace.org

0
Reply Shmuel 6/11/2007 11:06:33 AM

In Message-ID:<466cd85c$1@news.702com.net>,
"Gerard Schildberger" <Gerard46@rrt.net> wrote: 

>| Cruz, Jaime wrote:
>| Is there a way of getting REXX to display a number like 123456789 as
>| 123,456,789?  I'm done some google searches and so far I've come up
>| empty.  I would've SWORN there was a built-in method in REXX, but I
>| can't seem to find it.
>
>Below is a general purpose routine to add commas to any
>form of REXX number, including those in scientific
>notation, fractions, numbers with a leading sign,
>leading/trailing/imbedded blanks, numbers with
>leading/trailing currenty sign(s), etc.   Other than the
>insertions, the format of the number isn't compromised.

     I would never attempt to compete with Gerard for efficiency,
compactness, or scope.  However, I think the following might be
more understandable (if that's a consideration).  I use it as an
external subroutine, and, because it treats the number as mere
symbols, it shouldn't be dependent on the NUMERIC DIGITS setting.
Of course, it doesn't support the wide range of numeric formats or
other options that Gerard's does.

  int = arg(1)
  dot = pos('.',int)
  if dot = 0 then dot = length(int) + 1
  if dot < 5 then return int
  do i = dot-4 to 1 by -3 while datatype(substr(int,i,1),'N')
    int = insert(',',int,i)
  end
  return int

     I think that if I didn't have to worry about negative
numbers, I could drop the "while" clause.

     Patrick's method supports neither non-integers nor negative
numbers.  It could be modified to work, but for some reason I
always like to look for solutions which don't use the "reverse"
function.

-- 
Arthur T. - ar23hur "at" intergate "dot" com
Looking for a z/OS (IBM mainframe) systems programmer position
0
Reply Arthur 6/11/2007 3:35:11 PM

In <f4k6ua$lv0$1@reader2.panix.com>, on 06/11/2007
   at 07:14 PM, richgr@panix.com (Rich Greenberg) said:

>Some versions of Rexx have a FORMAT bif that will do the job nicely.

How do you get FORMAT to insert commas?


                                                                                 
                                                                               
 
  
>>  FORMAT(number                                                          >
  
                                                                               
 
  
>                                                                   )     ><
  
        ,                                                                        
  
             before      ,                                                     
  
                              after      ,                                     
  
                                              expp      ,expt                  
  
                                                                               
 
                                                                                  

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamtrap@library.lspace.org

0
Reply Shmuel 6/11/2007 7:05:28 PM

In article <oF2bi.3210$c45.842@trndny06>, Cruz, Jaime <Spammers@Bite.Me> wrote:
>Is there a way of getting REXX to display a number like 123456789 as 
>123,456,789?  I'm done some google searches and so far I've come up 
>empty.  I would've SWORN there was a built-in method in REXX, but I 
>can't seem to find it.

Some versions of Rexx have a FORMAT bif that will do the job nicely.

VM/CMS Rexx has it, don't know about others.

-- 
Rich Greenberg  N Ft Myers, FL, USA richgr atsign panix.com  + 1 239 543 1353
Eastern time.  N6LRT  I speak for myself & my dogs only.    VM'er since CP-67
Canines:Val, Red, Shasta & Casey (RIP), Red & Zero, Siberians  Owner:Chinook-L
Retired at the beach                                     Asst Owner:Sibernet-L
0
Reply richgr 6/11/2007 7:14:18 PM

| Rich Greenberg wrote:
|> Cruz, Jaime wrote:
|>Is there a way of getting REXX to display a number like 123456789 as
|>123,456,789?  I'm done some google searches and so far I've come up
|>empty.  I would've SWORN there was a built-in method in REXX, but I
|>can't seem to find it.

| Some versions of Rexx have a FORMAT bif that will do the job nicely.
|
| VM/CMS Rexx has it, don't know about others.

One trouble with using the FORMAT  bif  is that is changes (er, re-
formats) the number, including removing leading superflous zeroes,
striping plus signs, adding a leading zero if not present for
decimal fractions, changing the "format" of a number to conform to
the current  NUMERIC DIGITS  (either removing the  E+nnn  or  adding
an  E+nnn), etc.   Also, any leading/trailing/imbedded blanks are
removed  (which may or may not be a good thing from the user's point
of view. ____________________________________________________Gerard S.

 


0
Reply Gerard 6/11/2007 7:40:21 PM

| Arthur T. wrote:
|> Gerard Schildberger wrote:
|>| Cruz, Jaime wrote:
|>| Is there a way of getting REXX to display a number like 123456789 as
|>| 123,456,789?  I'm done some google searches and so far I've come up
|>| empty.  I would've SWORN there was a built-in method in REXX, but I
|>| can't seem to find it.

|> Below is a general purpose routine to add commas to any
|> form of REXX number, including those in scientific
|> notation, fractions, numbers with a leading sign,
|> leading/trailing/imbedded blanks, numbers with
|> leading/trailing currenty sign(s), etc.   Other than the
|> insertions, the format of the number isn't compromised.

|     I would never attempt to compete with Gerard for efficiency,
| compactness, or scope.  However, I think the following might be
| more understandable (if that's a consideration).  I use it as an

Hee hee hee... guilty as charged.  In my defense, I thought my
routine was (of course!!) self-documentating, as all my REXX code
is, so I didn't feel the need to add comments!!   Seriously folks,
the code is, in fact, just one line long (with the use of two
other one-line subroutines), and I broke up the REXX code (for
the posting here to COMP.LANG.REXX) to make it easier to peruse.

I use this commatizing code so often that I don't bother to
commentize it (to reduce bulk).  A lot of my code has a lot of
this type of one-liners (subroutines) in it, with the
documentation being external to the code.

My  COMMA  subroutine has evolved many times over the years and
is now (probably) in its present stable state  (that is, I've
stopped adding code-bloat, er, I mean, features),  albeit
rather obtuse, and, even I have to admit, hard on the eyeballs
to read.  I've tried to accomodate all types of REXX numbers,
no exuses for limited or varying NUMERIC DIGITS or NUMERIC FORM,
or for that matter, currency symbols (including those that are
unknown), all the while preserving the original intent (content
structure) of the number.

Understanding the code, of course, isn't for the feint of heart,
even with (as yet, non-existent) comments. ________________Gerard S.





| external subroutine, and, because it treats the number as mere
| symbols, it shouldn't be dependent on the NUMERIC DIGITS setting.
| Of course, it doesn't support the wide range of numeric formats or
| other options that Gerard's does.
|
|  int = arg(1)
|  dot = pos('.',int)
|  if dot = 0 then dot = length(int) + 1
|  if dot < 5 then return int
|  do i = dot-4 to 1 by -3 while datatype(substr(int,i,1),'N')
|    int = insert(',',int,i)
|  end
|  return int
|
|     I think that if I didn't have to worry about negative
| numbers, I could drop the "while" clause.
|
|     Patrick's method supports neither non-integers nor negative
| numbers.  It could be modified to work, but for some reason I
| always like to look for solutions which don't use the "reverse"
| function.


0
Reply Gerard 6/11/2007 7:58:42 PM

This was posted a long time ago

/* tst.rex */
x=123456789
y=comma(x)
say x y
comma:
return 
strip(reverse(translate("abc,def,ghi,jkl,mno,pqr,stu,vwx,yz",reverse(arg(1)),"abcdefghijklmnopqrstuvwxyz",",")),"L",",")

HTH,
Ven


"Cruz, Jaime" <Spammers@Bite.Me> wrote in message 
news:oF2bi.3210$c45.842@trndny06...
> Is there a way of getting REXX to display a number like 123456789 as 
> 123,456,789?  I'm done some google searches and so far I've come up empty. 
> I would've SWORN there was a built-in method in REXX, but I can't seem to 
> find it.
>
> -- 
> Jaime A. Cruz
> President
> Nassau Wings Motorcycle Club
> http://www.nassauwings.org/
> Member-at-Large
> AMA District 34
> http://www.AMADistrict34.com/
> Pop's Run
> http://www.popsrun.org/ 


0
Reply Ven 6/12/2007 10:32:36 AM

Rich Greenberg wrote:
> In article <oF2bi.3210$c45.842@trndny06>, Cruz, Jaime <Spammers@Bite.Me> wrote:
>> Is there a way of getting REXX to display a number like 123456789 as 
>> 123,456,789?  I'm done some google searches and so far I've come up 
>> empty.  I would've SWORN there was a built-in method in REXX, but I 
>> can't seem to find it.
> 
> Some versions of Rexx have a FORMAT bif that will do the job nicely.
> 
> VM/CMS Rexx has it, don't know about others.
> 

That must be where I've seen it!  I'm a "Mainframe Guy!"  Thanks... I'm 
looking at the other functions that were contributed to this thread 
since the script I'm playing with is not run on the mainframe.

-- 
Jaime A. Cruz
President
Nassau Wings Motorcycle Club
http://www.nassauwings.org/
Member-at-Large
AMA District 34
http://www.AMADistrict34.com/
Pop's Run
http://www.popsrun.org/
0
Reply Cruz 6/13/2007 11:26:35 AM

On 11 Jun, 05:18, black.hole.4.s...@gmail.com (Don Hills) wrote:
> In article <136pet08i4ko...@corp.supernews.com>,
> p...@interlog.com (Patrick TJ McPhee) wrote:
>
>
>
> >I seem to recall seeing a clever way to do this using translate().
>
> You can reorder characters with translate(), but not insert characters as
> far as I know. For example, to reorder a mm/dd/yy date to yy/mm/dd:
>
> mm_dd_yy = '06/11/07'
> yy_mm_dd = translate('78612345', mm_dd_yy, '12345678')
>
> --
> Don Hills    (dmhills at attglobaldotnet)     Wellington, New Zealand
> "New interface closely resembles Presentation Manager,
>  preparing you for the wonders of OS/2!"
>     -- Advertisement on the box for Microsoft Windows 2.11 for 286

Yes you can insert characters:
ymd = '20061107'
dmy = translate('da/mb/ytuv',ymd,'ytuvmbda')

0
Reply Captain 6/13/2007 11:59:50 AM

> Yes you can insert characters:
> ymd = '20061107'
> dmy = translate('da/mb/ytuv',ymd,'ytuvmbda')

Well, it's probably semantics, but you've not inserted any characters, 
the output string from translate is the same length as its input string, 
'da/mb/ytuv' in this case(10). So you get a 10-characterstring from it.

-- 
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
0
Reply Steve 6/13/2007 1:00:11 PM

In a previous episode of comp.lang.rexx, Steve Swift was heard to say:
>> Yes you can insert characters:
>> ymd = '20061107'
>> dmy = translate('da/mb/ytuv',ymd,'ytuvmbda')
>
>Well, it's probably semantics, but you've not inserted any characters, 
>the output string from translate is the same length as its input string, 
>'da/mb/ytuv' in this case(10). So you get a 10-characterstring from it.

Yes, it's arguing semantics. :-)

The definition of translate() says that it operates on the input
string given in the first argument according to the translation tables
given in the second and third arguments, and that it doesn't insert any
characters into the input string.

But in the above trick the input string was placed in the second argument
and the overall effect of the instruction was to insert some characters
into it (as well as reordering the string).
-- 
---- Ian Collier : imc@comlab.ox.ac.uk : WWW page (including REXX section):
------ http://users.comlab.ox.ac.uk/ian.collier/imc.shtml

New to this group?  Answers to frequently-asked questions can be had from
http://www.rexxla.org/faq.html .
0
Reply imc 6/13/2007 3:18:17 PM

Ven Ilagan wrote:
> strip(reverse(translate("abc,def,ghi,jkl,mno,pqr,stu,vwx,yz",reverse(arg(1)),"abcdefghijklmnopqrstuvwxyz",",")),"L",",")

Nice!  But there's no need to call REVERSE twice; you can just call
RIGHT once to pad the input instead:

  strip(translate("ab,cde,fgh,ijk,lmn,opq,rst,uvw,xyz" ,
                  , right(arg(1),26,",") ,
                  , "abcdefghijklmnopqrstuvwxyz") ,
        , "L", ",")

�R
0
Reply Glenn 6/13/2007 11:40:15 PM

Gerard Schildberger wrote:
> | Cruz, Jaime wrote:
> | Is there a way of getting REXX to display a number like 123456789 as
> | 123,456,789?  I'm done some google searches and so far I've come up
> | empty.  I would've SWORN there was a built-in method in REXX, but I
> | can't seem to find it.
> 
> Below is a general purpose routine to add commas to any
> form of REXX number, including those in scientific
> notation, fractions, numbers with a leading sign,
> leading/trailing/imbedded blanks, numbers with
> leading/trailing currenty sign(s), etc.   Other than the
> insertions, the format of the number isn't compromised.
> 
> Provision is also included to specify what character
> is to be used for the insertion (default is the comma),
> what size period to use (default is three characters),
> and the number of insertions may also be limited.
> 
> Any size number can be processed, no matter what the
> setting of NUMERIC DIGITS.
> 
> It's not a small routine, but it does what it's
> supposed to.
> 
> =========================================================
> comma: procedure; parse arg _,c,s,t; c=pickblank(c,",")
> if \isint(s) | s<1 then s=3; n=_'.9'; #=123456789; k=0
> if \isint(t) then t=9999999
>   do j=verify(n,#'0',,verify(n,#"0.",'M'))-s-1 to ,
>        verify(n,#,"M") by -s while k<t
>   _=insert(c,_,j); k=k+1
>   end
> return _
> 
> isint: return datatype(arg(1),'W')
> 
> pickblank: procedure; parse arg x,y; arg xu
> if xu=='BLANK' then return ' '; return word(x y,1)
> =========================================================
> 
> 
> say comma('$123456.70')            ====> $123,456.90
> say comma(1234567.00e+01')         ====> 1,234,567.00e+01
> say comma(+6789)                   ====> +6,789
> say comma(123678,'.')              ====> 123.678
> say comma(123456789012,'blank',5)  ====> 12 34567 89012
> 
> ________________________________________________Gerard S.
> 
>  
> 

Thanks! It worked great but I did have to change "#" to "a" as 
apparently "#" is not valid for a variable name in Open Object REXX. 
That was the only change that I had to make.

I also put each instruction on it's own line so it's easier for ME to 
read. ;-)


-- 
Jaime A. Cruz
President
Nassau Wings Motorcycle Club
http://www.nassauwings.org/
Member-at-Large
AMA District 34
http://www.AMADistrict34.com/
Pop's Run
http://www.popsrun.org/
0
Reply Cruz 6/14/2007 2:45:25 AM

17 Replies
330 Views

(page loaded in 0.225 seconds)

Similiar Articles:


















7/24/2012 6:33:03 PM


Reply: