Commatizing numbers: Difference between revisions

m
added some verbage and whitespace (and other improvements) to the Rosetta Code task preamble.
(=={{header|Racket}}== implementation added)
m (added some verbage and whitespace (and other improvements) to the Rosetta Code task preamble.)
Line 6:
 
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.
 
Some of the commatizing rules (specified below) are arbitrary, but they'll be a part of this task requirements, if only to make the results consistent amongst national preferences and other disciplines.
Line 22:
Leading zeroes are never commatized.   The string   0000000005714.882   after commatization is:   0000000005,714.882
 
Any &nbsp; ''period'' &nbsp; (<big>.</big>) &nbsp; in a number is assumed to be a &nbsp; ''decimal point''.
 
The original string is never changed &nbsp; except &nbsp; by the addition of commas (&nbsp; [or whatever character(s) is/are used for insertion)], if at all.
 
Leading signs ('''+''', '''-''') are to be preserved (even superfluous signs).
Line 30:
Leading/trailing/imbedded blanks, tabs, and other whitespace are to be preserved.
 
::: E.gG.: &nbsp; +1024 &nbsp; &nbsp; &nbsp; bottles of beer on the wall.
 
The case (upper/lower) of the exponent indicator is to be preserved. &nbsp; E.g.: &nbsp; 4.8903d-002
Line 48:
Numbers may be terminated with any non-digit character, including subscripts and/or superscript: &nbsp; 4142135624² &nbsp; or &nbsp; 7320509076<sub>(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 &nbsp; ''period length'' &nbsp; can be specified &nbsp; (sometimes referred to as "thousands" or "thousands separators). &nbsp; The &nbsp; ''period length'' is&nbsp; can be defined as the length (or number) of the decimal digits between commas. &nbsp; The default period length is &nbsp; <big>3</big>.
 
::: E.gG.: &nbsp; in this example, the period length is five: &nbsp; 56789,12340,14148
 
The location of where to start the scanning for the target field (the numeric part) should be able to be specified. The default is 1&nbsp; (one)<big>1</big>.
 
The (numeric?)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:
The value of &nbsp; pi &nbsp; should be separated with blanks every 5 places past the decimal point,
<br>the Zimbabwe dollar amount should use a decimal point for the "comma" separator: