Commatizing numbers: Difference between revisions

Some HTML cleanup
(J)
(Some HTML cleanup)
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.
 
;taskTask:
 
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
Line 11:
 
The number may be part of a larger (non-numeric) string such as:
::::* «US$1744 millions»       ──or──
::::* ±25000 motes.
 
The string may possibly ''not'' have a number suitable for commatizing, so it should be untouched and ''no error generated''.
 
If any argument (option) is invalid, nothing is changed and no error ''need be'' generated (quiet execution, no fail execution).   Error message generation is optional.
 
The exponent part of a number is never commatized.   The following string isn't suitable for commatizing:   9.7e+12000
 
Leading zeroes are never commatized.   theThe string   0000000005714.882   after commatization is:   0000000005,714.882
 
Any period in a number is assumed to be a decimal point.
Line 28:
Leading signs ('''+''', '''-''') are to be preserved (even superfluous signs).
 
Leading/trailing/imbedded blanks, tabs, and other whitespace are to be preserved.   E.g.:   +1024     bottles of beer on the wall.
 
The case (upper/lower) of the exponent indicator is to be preserved.   E.g.:   4.8903d-002
 
Any exponent character(s) should be supported:
Line 41:
::::::* 1000**100
::::::* 2048²
::::::* 4096<sup>32</sup)>
::::::* 10000pow(pi)
 
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 (''',''')
character.
 
The ''period length'' can be specified (sometimes referred to as "thousands"). &nbsp; The ''period length'' is the length (or number) of the digits between commas. &nbsp; The default period length is 3.
default period length is 3. &nbsp;
 
E.g.: &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. &nbsp; The default is 1 (one).
 
The (numeric?) strings below may be placed in a file (and read) or stored as simple strings within the program.
Line 73 ⟶ 72:
::::* ␢␢␢$-140000±100 millions.
::::* 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).
 
;Also see:
* The Wiki entry: &nbsp; [http://en.wikipedia.org/wiki/Eddington_number Arthur Eddington's number of protons in the universe].
 
 
Anonymous user