Jump to content

Template:Number table sorting/doc

From Meta, a Wikimedia project coordination wiki

Nts stands for Number Table Sorting and is used to display numbers with thousands separator in a sortable table and have them numerically sorted in alphabetic sort mode. It is applied to all numbers of a column, in cases where numeric sort mode does not work or is not desired.

The supplied input numbers should not have thousands separators. Apart from the added thousands separators the numbers are formatted like supplied (scientific notation or not, leading and trailing zeros, and a zero before the decimal point or not). This formatting does not affect the sorting order except for numbers not satisfying the limitations mentioned below.

Purpose

[edit]

If some table cells in a column contain text after the number, or if the numbers are preceded by some fixed text other than a currency symbol, alphabetic sorting mode is needed.

Also, formerly, for table sorting to function correctly, numbers had to be entered with not more than one thousands separator. As a workaround alphabetic sorting mode was applied, and the numbers provided with a hidden part so that alphabetic sorting corresponded with numeric sorting. Since a mix in one column of numbers formatted for alphabetic sorting and plain numbers does not allow proper sorting, adding a number in an existing table may require putting it in the format used in that column.

Method

[edit]

This template automatically creates hidden code like <span style="display:none">&0000000123456789.001230</span> before the actual displayed number. The preceding ampersand forces the sorting routine to use text sort. The routine sorts the total text without the tags, which corresponds to numeric sorting due to the leading zeros.

Limitations

[edit]
  • Negative numbers do not sort correctly with this template: while they correctly come at the low end, mutually they are sorted in reverse order (i.e., in the order of the absolute value).
  • The maximum number is 1×1016. While larger numbers correctly come at the high end, they are mutually sorted alphabetically.
  • There is a maximum of 6 digits after the decimal separator. When using a consistent non-scientific notation numbers with more than 6 digits after the decimal separator still sort correctly. They sort correctly with respect to 0 if they are written with the zero before the decimal point.
  • In the case of text before a number, the entry is positioned like 1×1016. If there are more of such entries they are mutually sorted alphabetically (primarily based on the text).

Parameters

[edit]

The template has only one parameter: a real number without thousand separators.

Example

[edit]
{{Nts|123456789.00123}}

expands to

 <span style="display:none">&0000000123456789.001230</span> 123,456,789.00123 

which is rendered as &10000000123456789001230123,456,789.00123

Debug option

[edit]

"{{nts|123456789.00123|debug=yes}}" gives "&10000000123456789001230123,456,789.00123" [1]

More examples

[edit]

Below are more examples, also illustrating the limitations mentioned above.

Note: Javascript sorting order: &+,-.0123456789Ee~

sortkey and number
{{Number table sorting/Expression error: Unrecognized word "between". 1=Expression error: Unrecognized word "between".
}}between 2 and 3
{{Number table sorting/Expression error: Unrecognized word "approx". 1=Expression error: Unrecognized word "approx".
}}approx. 10
&09999999999999994999999−5
&09999999999999995999999−4
&09999999999999926999999−73
&09999999999999932999999−67
&10000000000123456000000123,456
~20,345,678,901,234,570.00000000
~100,345,678,901,234,560.00000000
&112345678901235000000001,234,567,890,123,456.00000000
&10234567890123460031250234,567,890,123,456.12000000
&1003456789012345600000034,567,890,123,456.12500000
&100045678901234560996094,567,890,123,456.12300000
&10000567890123456119995567,890,123,456.12340000
&1000006789012345612300167,890,123,456.12346000
&100000078901234561234997,890,123,456.12345700
&10000000890123456123460890,123,456.12345680
&1000000009012345612345690,123,456.12345678
&100000000001234561234560,123,456.12345678
&10000000000123456123456123,456.12345678
&1000000000002345612345623,456.12345678
&100000000000034561234563,456.12345678
&10000000000000456123456456.12345678
&1000000000000005612345656.12345678
&100000000000000061234566.12345678
&10000000000000000123456.12345678
&100000000000000001234560.12345678
&100000000000000000234560.02345678
&100000000000000000034560.00345678
&100000000000000000004560.00045678
&100000000000000000000560.00005678
&100000000000000000000060.00000678
&100000000000000000000000.00000078
&100000000000000000000000.00000008
&10000000000000000000000.00000008
&100000000000000000000000

See also

[edit]