Anonymous user
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 ''period'' (<big>.</big>) in a number is assumed to be a ''decimal point''.
The original string is never changed except by the addition of commas
Leading signs ('''+''', '''-''') are to be preserved (even superfluous signs).
Line 30:
Leading/trailing/imbedded blanks, tabs, and other whitespace are to be preserved.
::: E.
The case (upper/lower) of the exponent indicator is to be preserved. E.g.: 4.8903d-002
Line 48:
Numbers may be terminated with any non-digit character, including subscripts and/or superscript: 4142135624² or 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. The default is the comma (<big>''','''</big>)
character.
The ''period length'' can be specified (sometimes referred to as "thousands" or "thousands separators). The ''period length''
::: E.
The location of where to start the scanning for the target field (the numeric part) should be able to be specified. The default is
The
<br><br>
;Strings to be used as a minimum:
The value of pi 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:
|