Template:Number table sorting/doc

This template can be useful when building a sortable table in which a column contains both numbers and text. This template should be applied to every number in the column.

Currently, the template works for numbers less than or 10,000,000,000,000,000 (1×1016) and greater than -10,000,000,000,000,000 (-1×1016). Numbers outside this range will sort above or below other numbers depending on sign. See the Limitations section below.

By default the output is displayed using thousands separators. To display numbers as entered, use no.

The template generates a hidden "sort key" in the HTML markup which forces the Javascript sorting algorithm to sort the column alphabetically.

Purpose
There are at two cases where this template is useful:
 * 1) When numbers are followed by some text
 * 2) When numbers are preceded by some text other than a currency symbol.

Parameters
The template has only one required parameter: a real number. These examples use the name of the redirect, nts, for brevity.


 * Optional parameters
 * : To display some text before the number, use some prefix
 * : To retain a number's format, use no
 * : To display the sort key, use yes.
 * : To display the sort key, use yes.
 * : To display the sort key, use yes.
 * : To display the sort key, use yes.

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

Limitations

 * Any subset of numbers larger than 1×1016 are sorted as greater than 1×1016 but this subset is sorted alphabetically.
 * Any subset of numbers smaller than -1×1016 are sorted as less than -1×1016 but this subset is sorted alphabetically.
 * If a non-numeric value is given as the first unnamed parameter the results are undefined.
 * There is a maximum of 6 digits after the decimal separator. Positive numbers with more than 6 decimal digits should sort correctly but the results for negative numbers with more that 6 decimal digits is undefined.
 * A prefix (using the  parameter) does not affect the sort order.

Examples
→

For text which follows a number,  displays   with a numerical sort key of. This forces numerical sorting in the cell using this value instead of the default alphabetical sorting.

Below are more examples, some of which illustrate the limitations listed above.