Anonymous user
Commatizing numbers: Difference between revisions
m
→{{header|REXX}}: used better variable names, add/changed whitespace and comments.
(→top: add `⏨` [U+23E8 “decimal expnonent symbol”] exponent character list) |
m (→{{header|REXX}}: used better variable names, add/changed whitespace and comments.) |
||
Line 1,163:
=={{header|REXX}}==
The hardest part of the '''comma''' function is to locate where a ''usable'' number starts and ends.
<lang rexx>/*REXX program
@. =
@.1= "pi=3.14159265358979323846264338327950288419716939937510582097494459231"
Line 1,185:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
comma: procedure;
/* [↓] various error tests. */
if \datatype(
period==0 | , /*PERIOD can't be zero. */
/*some argument is invalid. */
digs= 123456789
if every<0 then do
else
beginning= verify(n, digs, "M") /*find beginning of the num. */
end
#= 0
if beginning>0 & ending>0 then
do j=ending to beginning by -period while #<times
_= insert(commaChar, _, j) /*insert a comma into string.*/
#= # + 1 /*bump the count of changes. */
end /*j*/ /*(maybe no changes are made)*/
return _ /*return the commatized str. */
</lang>
{{out|output|text= when using the internal default inputs:}}
<pre>
|