Commatizing numbers: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: corrected a typo.)
m (added whitespace to the task's preamble.)
Line 3: Line 3:
''Commatizing''   numbers (as used here, a handy expedient made-up word) is the act of adding commas to a number (or string), or the numeric part of a larger string.
''Commatizing''   numbers (as used here, a handy expedient made-up word) is the act of adding commas to a number (or string), or the numeric part of a larger string.


;Task:


;Task:
Write a function that takes a string as an argument with optional arguments or parameters (the format of parameters/options is left to the programmer) that in general, adds commas (or some
Write a function that takes a string as an argument with optional arguments or parameters (the format of parameters/options is left to the programmer) that in general, adds commas (or some
other characters, including blanks or tabs) to the first numeric part of a string (if it's suitable for commatizing as per the rules below), and returns that newly commatized string.
other characters, including blanks or tabs) to the first numeric part of a string (if it's suitable for commatizing as per the rules below), and returns that newly commatized string.
Line 14: Line 14:
::::*   ±25000 motes.
::::*   ±25000 motes.


<br>
The string may possibly ''not'' have a number suitable for commatizing, so it should be untouched and ''no error generated''.
The string may possibly ''not'' have a number suitable for commatizing, so it should be untouched and ''no error generated''.


Line 32: Line 33:
::* &nbsp; the case (upper/lower) of the exponent indicator, e.g.: &nbsp; 4.8903d-002
::* &nbsp; the case (upper/lower) of the exponent indicator, e.g.: &nbsp; 4.8903d-002


<br>
Any exponent character(s) should be supported:
Any exponent character(s) should be supported:
::::::* &nbsp; 1247e12
::::::* &nbsp; 1247e12
Line 44: Line 46:
::::::* &nbsp; 10000pow(pi)
::::::* &nbsp; 10000pow(pi)


Numbers may be terminated with any non-digit character, including subscripts and/or superscript: &nbsp; 4142135624² &nbsp; or &nbsp; 7320509076<sub>(base 24)</sub>.
<br>Numbers may be terminated with any non-digit character, including subscripts and/or superscript: &nbsp; 4142135624² &nbsp; or &nbsp; 7320509076<sub>(base 24)</sub>.


The character(s) to be used for the comma can be specified, and may contain blanks, tabs, and other whitespace characters, as well as multiple characters. &nbsp; The default is the comma (<big>''','''</big>) character.
The character(s) to be used for the comma can be specified, and may contain blanks, tabs, and other whitespace characters, as well as multiple characters. &nbsp; The default is the comma (<big>''','''</big>) character.
Line 55: Line 57:


The character strings below may be placed in a file (and read) or stored as simple strings within the program.
The character strings below may be placed in a file (and read) or stored as simple strings within the program.
\
<br><br>

;Strings to be used as a minimum:
;Strings to be used as a minimum:
The value of &nbsp; pi &nbsp; should be separated with blanks every 5 places past the decimal point,
The value of &nbsp; pi &nbsp; should be separated with blanks every 5 places past the decimal point,
Line 72: Line 75:
:* &nbsp; 6/9/1946 was a good year for some.
:* &nbsp; 6/9/1946 was a good year for some.
<br>where the penultimate string has three leading blanks &nbsp; (real blanks are to be used).
<br>where the penultimate string has three leading blanks &nbsp; (real blanks are to be used).



;Also see:
;Also see: