Anonymous user
Commatizing numbers: Difference between revisions
m
→{{header|REXX}}: added more comments, broke up multiple statement lines.
m (→{{header|REXX}}: removed the need for the P function.) |
m (→{{header|REXX}}: added more comments, broke up multiple statement lines.) |
||
Line 282:
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────COMMA subroutine────────────────────*/
comma: procedure; parse arg _,c,p,t,s
c=word(c ',', 1) /*get the commatizing char(s).*/
if cU=='BLANK' then c=' ' /*special case for a "blank" sep.*/
o=word(p 3, 1) /*get the optional period length.*/
p=abs(o) /*get
t=word(t 999999999, 1) /*get max# of "commas" to insert.*/
s=word(s 1, 1) /*get optional start position. */
if \datatype(p,'W') | \datatype(t,"W") | \datatype(s,'W') |,
t<1 | s<1 | p==0 | arg()>5 then return _ /*invalid options?*/
n=_'.9'; #=123456789; k=0 /*define some handy-dandy vars. */
if o<0 then do /*using a negative period length.*/
b=verify(_,' ', , s) /*position of 1st blank in string*/
Line 299 ⟶ 305:
e=verify(n, #'0', , max(1, verify(n, #"0.", 'M', s))) - p - 1
end
if e>0 & b>0 then do j=e to b by -p while k<t /*commatize the digs*/
_=insert(c, _, j) /*comma spray ──► #.*/
k=k+1 /*bump commatizing. */
end /*j*/
return _</lang>
'''output''' when using the internal strings for input:
<pre>
|