Cheers,
Jay
Guy LHeureux wrote:
> Does anyone know of an easy way to format numbers into numbers with the
> commas in the correct location, ie 123456789 becomes 123,456,789.
>
> Thanks
>
> ----------------------------------------------------------------------
> For TSO-REXX subscribe / signoff / archive access instructions,
> send email to LIST...@VM.MARIST.EDU with the message: INFO TSO-REXX
----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to LIST...@VM.MARIST.EDU with the message: INFO TSO-REXX
RECVAL = STRIP(SPACE( ,
TRANSLATE("ABC,DEF,GHI,JKL", ,
RIGHT(RECVAL,12), "ABCDEFGHIJKL"), 0) , , ",")
where RECVAL is a variable name of your choice and holds the number without
the commas before the statement is executed and will have the commas after
the statement is executed.
In a message dated 05/02/2002 7:38:00 PM Eastern Daylight Time,
Thanks
----------------------------------------------------------------------
I guess I'm just too dense to figure out how to make this work for any number (or it is getting late)...
Here is another little routine to format any number with commas (it also handles numbers with decimal places).
/* rexx - commafy */
arg num
revnum = reverse(num)
if pos('.',revnum) <> 0 then
parse var revnum mantissa '.' revnum
else
mantissa = ''
do while start < length(revnum) - 4
start = lastpos(',',revnum) + 3
revnum = insert(',',revnum,start)
end
num = reverse(revnum)
if mantissa <> '' then num = num || '.' || reverse(mantissa)
say num
I think there was also something (a little more elegant than mine) about this a few months ago on the list. Take a look in the archives.
HTH,
Rob
Well, it's easy, 'cause the routine is already written. It will commatize
any number, no restrictions on DIGITS(), handle signed numbers, numbers
with decimal points and/or fractions, as well as exponentated numbers. It
also can support "European" style numbers with periods (or any other
characters) for "commas". Example of use: newnum = comma(num)
___________________________________________________________________________
comma: procedure; parse arg _,c; if c=='' then c=","; n=_'.9'
do j=verify(n,1234567890,,verify(n,1234567890.,'M'))-4 to ,
verify(n,987654321,"M") by -3;_=insert(c,_,j)
end
return _
__________________________________________________________________Gerard S.
i wrote something like this for a friend. the program works in both directions but with german rules (decimalpoint is comma)
in: 123456 # out: 123.456
in: 12345,67 # out 1.2345,67
usage: print_formatted = pu§fmt$e("12345,67","D")
or
in: 12.345.678 # out: 12345678
in: 12.345,78 # out: 12345,78
usage: computational = pu§fmt$e("12.345,67","R")
i stay here only with my windows-pc without rexx and cannon test. so, all what you have to do is to change decimalpoint from "," to "." and the thousand-point from "." to ","
have fun
Heinz
/* PU§FMT$E **********************************************************
* *
* Formatierung von Zahlen. *
* Parameter 1. zu formatierende Zahl *
* 2. Formatierungsart *
* D = Druckaufbereitet *
* R = Rechenf„hig *
* *
* Erstellt: 29.06.1999 Wittemann *
* *
*********************************************************************/
H_PROG_START:
parse source . TYP .
if TYP = "FUNCTION" then arg WERT,ART,DMY
else arg WERT ART DMY
WERT = strip(WERT)
if ART <> "R" then ART = "D"
select
when ART = "R" then call format_rechenfaehig
when ART = "D" then call format_druckaufbereitet
otherwise nop
end
H_PROG_START:
return NEW
format_rechenfaehig:
/******************************************************************
* Druckaufbereitungspunkte entfernen, Dezimal "." statt "," *
******************************************************************/
parse var WERT INTEGER "," DECIMAL
NEW = space(translate(INTEGER," ","."),0)
if DECIMAL <> "" then NEW = NEW"."DECIMAL
return NEW
format_druckaufbereitet:
/******************************************************************
* Tausender "." setzen, Dezimal "," statt "." *
******************************************************************/
parse var WERT INTEGER "." DECIMAL
INTEGER = reverse(INTEGER)
NEW=""
do I = 1 to length(INTEGER)
NEW = NEW !! substr(INTEGER,I,1)
if I // 3 = 0 then do
NEW = NEW"."
end
end
NEW = reverse(NEW)
if left(NEW,1) = "." then NEW = substr(NEW,2)
if DECIMAL <> "" then NEW = NEW","DECIMAL
return NEW
TSO REXX Discussion List <TSO-...@VM.MARIST.EDU> schrieb am 03.05.02:
> Does anyone know of an easy way to format numbers into numbers with the
> commas in the correct location, ie 123456789 becomes 123,456,789.
>
> Thanks
>
> ----------------------------------------------------------------------
> For TSO-REXX subscribe / signoff / archive access instructions,
> send email to LIST...@VM.MARIST.EDU with the message: INFO TSO-REXX
______________________________________________________________________________
All inclusive! 100 MB Speicher, werbefrei, SMS günstiger, Wunschrufnummer, Events,
Preisvorteile und mehr unter http://club.web.de/?mc=021104
EDMK will only handle integers, not numbers in general. It also has a length
restriction, and can't handle exponentated numbers and other such oddities.
________________________________________________________________Gerard S.
> Does anyone know of an easy way to format numbers into numbers with the
> commas in the correct location, ie 123456789 becomes 123,456,789.
DFSORT's INREC, OUTREC and OUTFIL OUTREC statements allow you to use 27
pre-defined edit masks or your own user defined edit masks for this kind of
thing. For example, p,9,ZD,EDIT=(TTT,TTT,TTT) if you want to print leading
zeros or p,9,ZD,EDIT=(III,III,IIT) if you don't want to suppress leading
zeros or M12 if you want a sign and suppressed leading zeros. Lots of
variations are possible. If you want more help using DFSORT for this, let
me know exactly what your input values look like and what you want your
output values to look like in terms of signs, leading zeros, etc.
--
Frank Yaeger - DFSORT Team
Specialties: ICETOOL, OUTFIL, Symbols, Migration
=> DFSORT/MVS is on the WWW at http://www.ibm.com/storage/dfsort/
> ... p,9,ZD,EDIT=(III,III,IIT) if you don't want to suppress leading
> zeros ...
Sorry, that should be "if you want to suppress leading zeros".
Gary Weinhold
Data Kinetics, Ltd
Gary Weinhold
<weinhold To: TSO-...@VM.MARIST.EDU
@DKL.COM> cc:
Sent by: TSO Subject: Re: Way to Format numbers with commas
REXX
Discussion
List
<TSO-REXX
05/03/02
01:19 PM
Please
respond to
TSO REXX
Discussion
List