Commatizing numbers: Difference between revisions
Content deleted Content added
J |
Some HTML cleanup |
||
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: |
||
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 |
||
Line 11: | Line 11: | ||
The number may be part of a larger (non-numeric) string such as: |
The number may be part of a larger (non-numeric) string such as: |
||
::::* «US$1744 millions» |
::::* «US$1744 millions» ──or── |
||
::::* ±25000 motes. |
::::* ±25000 motes. |
||
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''. |
||
If any argument (option) is invalid, nothing is changed and no error ''need be'' generated (quiet execution, no fail execution). |
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 exponent part of a number is never commatized. The following string isn't suitable for commatizing: 9.7e+12000 |
||
Leading zeroes are never commatized. |
Leading zeroes are never commatized. The string 0000000005714.882 after commatization is: 0000000005,714.882 |
||
Any period in a number is assumed to be a decimal point. |
Any period in a number is assumed to be a decimal point. |
||
Line 28: | Line 28: | ||
Leading signs ('''+''', '''-''') are to be preserved (even superfluous signs). |
Leading signs ('''+''', '''-''') are to be preserved (even superfluous signs). |
||
Leading/trailing/imbedded blanks, tabs, and other whitespace are to be preserved. |
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. |
The case (upper/lower) of the exponent indicator is to be preserved. E.g.: 4.8903d-002 |
||
Any exponent character(s) should be supported: |
Any exponent character(s) should be supported: |
||
Line 41: | Line 41: | ||
::::::* 1000**100 |
::::::* 1000**100 |
||
::::::* 2048² |
::::::* 2048² |
||
::::::* 4096<sup>32</sup |
::::::* 4096<sup>32</sup> |
||
::::::* 10000pow(pi) |
::::::* 10000pow(pi) |
||
Numbers may be terminated with any non-digit character, including subscripts and/or superscript. |
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 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 (''',''') |
||
character. |
character. |
||
The ''period length'' can be specified (sometimes referred to as "thousands"). |
The ''period length'' can be specified (sometimes referred to as "thousands"). The ''period length'' is the length (or number) of the digits between commas. The default period length is 3. |
||
default period length is 3. |
|||
E.g.: |
E.g.: in this example, the period length is five: 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 location of where to start the scanning for the target field (the numeric part) should be able to be specified. 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. |
The (numeric?) strings below may be placed in a file (and read) or stored as simple strings within the program. |
||
Line 73: | Line 72: | ||
::::* ␢␢␢$-140000±100 millions. |
::::* ␢␢␢$-140000±100 millions. |
||
::::* 6/9/1946 was a good year for some. |
::::* 6/9/1946 was a good year for some. |
||
<br>where the penultimate string has three leading blanks |
<br>where the penultimate string has three leading blanks (real blanks are to be used). |
||
;Also see: |
;Also see: |
||
* The Wiki entry: |
* The Wiki entry: [http://en.wikipedia.org/wiki/Eddington_number Arthur Eddington's number of protons in the universe]. |
||