Content deleted Content added
→Sort key: new section explaining the sort key |
+cat |
||
(33 intermediate revisions by 25 users not shown) | |||
Line 1:
{{Documentation subpage}}
{{High-use}}
{{Template shortcut|Nts}}
{{Lua|Module:Number table sorting}}
{{mbox
This template can be useful when building a [[Help:Sorting|sortable table]] in which a column contains both numbers and text. This template should be applied to every number in the column. ▼
| type = notice
| text = Note. Adding <code>data-sort-type="number"</code> to the relevant column header solves many numerical sorting problems. See {{slink|Help:Sortable tables#Forcing a column to have a particular data type}}.
}}
▲This template can be useful when building a [[Help:
Currently, the template works for numbers between −10<sup>308</sup> and 10<sup>308</sup>. Numbers outside this range will sort above or below other numbers depending on sign. See the [[#Limitations|Limitations]] section below.
By default the output is displayed using thousands separators. To display numbers as entered, use {{para|format|no}}.
The template generates a hidden "sort key" in the [[HTML]] markup which forces the [[
===Purpose===
Line 14 ⟶ 19:
# When numbers are followed by some text
# When numbers are preceded by some text other than a currency symbol.
Note that some text that follows numbers is no longer a problem, and the column will still sort numerically. The percent symbol (%) for example. Or references. And that is without adding <code>data-sort-type=number</code> to the header. See: [[Help:Sortable tables#Numerical sorting problems]] for much more info.
==Parameters==
Line 21 ⟶ 27:
* <code>prefix</code>: To display some text before the number, use {{para|prefix|''some prefix''}}
*: <code><nowiki>{{nts|123456789.00123|prefix=approx.&nbsp;}}</nowiki></code> → {{nts|123456789.00123|prefix=approx. }}
* <code>format</code>: For unformatted
*: <code><nowiki>{{nts|123456789.00123}}</nowiki></code> → {{nts|123456789.00123}}
*: <code><nowiki>{{nts|123456789.00123|format=no}}</nowiki></code> → {{nts|123456789.00123|format=no}}
Line 28 ⟶ 34:
*: <code><nowiki>{{nts|-123456789.00123|debug=yes}}</nowiki></code> → {{nts|-123456789.00123|debug=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.
{{TemplateDataHeader}}
<templatedata>
{
"description": "",
"params": {
"1": {
"label": "Number",
"type": "number",
"required": true,
"description": "Your number"
},
"format": {
"label": "Format output?",
"type": "string",
"required": false,
"description": "If you do not wish the output to be formatted (i.e. separated by thousand separators), please put \"no\" in this field. (Without quotation marks.)"
},
"debug": {
"label": "Debug",
"type": "string",
"required": false,
"description": "If set to \"yes\", forces output to include debug data"
},
"prefix": {
"label": "Prefix",
"type": "string",
"required": false,
"description": "The prefix to be displayed before the number. E.g. \"Approx.\" or \"$\""
}
}
}
</templatedata>
==Sort key==
Line 68 ⟶ 107:
|-
| <code><nowiki>{{nts|between 2 and 3|debug=yes}}</nowiki></code> || {{nts|between 2 and 3|debug=yes}}
|-
| <code><nowiki>{{nts|between 2 and 3|debug=no}}</nowiki></code> || {{nts|between 2 and 3|debug=no}}
|-
| <code><nowiki>{{nts|10|prefix=approx.{{sp}}|debug=yes}}</nowiki></code> || {{nts|10|prefix=approx.{{sp}}|debug=yes}}
Line 145 ⟶ 186:
==See also==
* {{tl|
* {{tl|Hidden sort key}}
* {{tl|
* {{tl|val}}—displays numbers and quantities with various formatting options
▲* {{tl|Dts}} - for sorting dates
▲* {{tl|Sms}}
<includeonly>{{sandbox other||
[[Category:Sorting templates|
[[Category:Table templates]]
}}</includeonly>▼
▲</includeonly>
|