Anonymous user
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.
;
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»
::::* ±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).
The exponent part of a number is never commatized.
Leading zeroes are never commatized.
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.
The case (upper/lower) of the exponent indicator is to be preserved.
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.
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.
character.
The ''period length'' can be specified (sometimes referred to as "thousands").
E.g.:
The location of where to start the scanning for the target field (the numeric part) should be able to be specified.
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
;Also see:
* The Wiki entry:
|