Anonymous user
Commatizing numbers: Difference between revisions
m
→{{header|REXX}}: corrected a typo, changed indentation for the function, added whitespace.
m (→{{header|REXX}}: used a template for the output section.) |
m (→{{header|REXX}}: corrected a typo, changed indentation for the function, added whitespace.) |
||
Line 800:
=={{header|REXX}}==
The hardest part of the '''comma''' function is to locate where a
<lang rexx>/*REXX program add commas (or other chars) to a number within a string (or a char str).*/
@. =
@.1= "pi=3.14159265358979323846264338327950288419716939937510582097494459231"
@.2= "The author has two Z$100000000000000 Zimbabwe notes (100 trillion)."
@.3= "-in Aus$+1411.8millions"
@.4= "===US$0017440 millions=== (in 2000 dollars)"
@.5= "123.e8000 is pretty big."
@.6= "The land area of the earth is 57268900(29% of the surface) square miles."
@.7= "Ain't no numbers in this here words, nohow, no way, Jose."
@.8= "James was never known as 0000000007"
@.9= "Arthur Eddington wrote: I believe there are 15747724136275002577605653961181555468044717914527116709366231425076185631031296 protons in the universe."
@.10= " $-140000±100 millions."
@.11= "6/9/1946 was a good year for some."
do i=1 while @.i\==''; if i\==1 then say /*process each string.*/
say '
if i==1 then say '
if i==2 then say '
if i>2 then say '
end /*j*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
comma: procedure; parse arg _,c,p,t,s /*
arg ,cU . /*
c=word(c ',', 1) /*
if cU=='BLANK' then c=' ' /*special case for a "blank"
o=word(p 3, 1) /*
p=abs(o) /*
t=word(t 999999999, 1) /*
s=word(s 1, 1) /*
if \datatype(p, 'W') | \datatype(t, "W") | \datatype(s, 'W') | ,
t<1 | s<1 | p==0 | arg()>5 then return _ /*any invalid options? */
n=_'.9'; #=123456789; k=0 /*define some handy-dandy
if o<0 then do /*using a negative period length
b=verify(_, ' ', , s) /*position of
e=length(_) - verify( reverse(_), ' ') + 1 - p
end
else do /*using a positive period length. */
b=verify(n, #,
z=max(1, verify(n, #
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
_=insert(c, _, j) /*comma spray
k= k + 1 /*bump the commatizing.
end /*j*/
return _</lang>
{{out|output|text= when using the internal default inputs:}}
<pre>
|