Bản mẫu:Number table sorting

Bách khoa toàn thư mở Wikipedia
(Đổi hướng từ Bản mẫu:Nts)
Tài liệu bản mẫu[xem] [sửa] [lịch sử] [làm mới]

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 between −10308 and 10308. 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 |format=no.

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

Mục đích[sửa mã nguồn]

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.

Các thông số[sửa mã nguồn]

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

Các thông số tùy chọn
  • prefix: To display some text before the number, use |prefix=some prefix
    {{nts|123456789.00123|prefix=approx. }}&0000000123456789001230approx. 123.456.789,00123
  • format: For unformatted output, use |format=no
    {{nts|123456789.00123}}&0000000123456789001230123.456.789,00123
    {{nts|123456789.00123|format=no}}&0000000123456789001230123456789.00123
  • debug: To display the sort key, use |debug=yes.
    {{nts|123456789.00123|debug=yes}}&0000000123456789001230123.456.789,00123
    {{nts|-123456789.00123|debug=yes}}&-1-1-1-1-1-1-1-2-3-4-5-6-7-8-90998769−123.456.789,00123

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.

Đây là tài liệu Dữ liệu bản mẫu cho bản mẫu này được sử dụng bởi Trình soạn thảo trực quan và các công cụ khác; xem báo cáo sử dụng tham số hàng tháng cho bản mẫu này.

Dữ liệu bản mẫu cho Number table sorting

Tham số bản mẫu[Quản lý Dữ liệu bản mẫu]

Tham sốMiêu tảKiểuTrạng thái
Number1

Your number

Sốbắt buộc
Format output?format

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.)

Chuỗi dàitùy chọn
Debugdebug

If set to "yes", forces output to include debug data

Chuỗi dàitùy chọn
Prefixprefix

The prefix to be displayed before the number. E.g. "Appox." or "$"

Chuỗi dàitùy chọn

Sắp xếp chủ chốt[sửa mã nguồn]

The sort key is a nineteen-digit number. For numbers within range the first four digits are determined by the number's sign and order of magnitude and the next fifteen digits are determined by the number's sign and significand.

Số trong phạm vi
  • For numbers between 10−308 and 10308 the first four digits are calculated by adding 7000 to the order of magnitude and the next fifteen digits are calculated by multiplying the significand by 1014.
  • For numbers between −10−308 and −10308 the first four digits are calculated by subtracting the order of magnitude from 2999 and the next fifteen digits are calculated by subtracting the significand from 10 multiplying the difference by 1014.
  • The sort key for 0 is 5000000000000000000.
Số ra khỏi phạm vi
  • Numbers larger than 10308 are assigned the sort key 9000000000000000000.
  • Numbers smaller than −10308 are assigned the sort key 1000000000000000000.
  • Numbers between 10−308 and 0 or between 0 and −10−308 are assigned the sort key 5000000000000000000.

Hạn chế[sửa mã nguồn]

  • Any subset of numbers larger than 10308 are sorted together.
  • Any subset of numbers smaller than −10308 are sorted together.
  • Any subset of numbers between 10−308 and −10−308 are sorted together.
  • If a non-numeric value is given as the first unnamed parameter the results are undefined.
  • The hyphen minus sign is converted into a true minus sign; note, though, that this means no more than 12 significant figures are possible.
  • A prefix (using the prefix parameter) does not affect the sort order.

Các ví dụ[sửa mã nguồn]

{{nts|123456789.00123}}&0000000123456789001230123.456.789,00123

For text which follows a number, {{nts|123,456}} as of 2012 displays 123,456 as of 2012 with a numerical sort key of 123456. 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.

Mã wiki Sắp xếp chủ chốt và số error spillover
{{nts|debug=yes}}
{{nts||debug=yes}}
{{nts|between 2 and 3|debug=yes}} &Lỗi biểu thức: Từ “between” không rõ ràngbetween 2 and 3
{{nts|between 2 and 3|debug=no}} &Lỗi biểu thức: Từ “between” không rõ ràngbetween 2 and 3
{{nts|10|prefix=approx.{{sp}}|debug=yes}} &0000000000000010000000approx. 10
{{nts|-5|debug=yes}} &-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-5000000−5
{{nts|-4|debug=yes}} &-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-4000000−4
{{nts|-73|debug=yes}} &-1-1-1-1-1-1-1-1-1-1-1-1-1-1-8-3000000−73
{{nts|-67|debug=yes}} &-1-1-1-1-1-1-1-1-1-1-1-1-1-1-7-7000000−67
{{nts|-20345678901234567.12345678|debug=yes}} &-21-4-5-6-7-8-90-1-2-3-4-5-6-7-8000000−20.345.678.901.234.570,00000000
{{nts|123.456e3|debug=yes}} &0000000000123456000000123.456
{{nts|123.456e2|debug=yes}} &000000000001234560000012.345,6
{{nts|20345678901234567.12345678|debug=yes}} &~20.345.678.901.234.570,00000000
{{nts|100345678901234567.12345678|debug=yes}} &~100.345.678.901.234.560,00000000
{{nts|1234567890123456.12345678|debug=yes}} &12345678901234560000001.234.567.890.123.456,00000000
{{nts|234567890123456.12345678|debug=yes}} &0234567890123456125000234.567.890.123.456,12000000
{{nts|34567890123456.12345678|debug=yes}} &003456789012345612500034.567.890.123.456,12500000
{{nts|4567890123456.12345678|debug=yes}} &00045678901234561230464.567.890.123.456,12300000
{{nts|567890123456.12345678|debug=yes}} &0000567890123456123413567.890.123.456,12340000
{{nts|67890123456.12345678|debug=yes}} &000006789012345612345867.890.123.456,12346000
{{nts|7890123456.12345678|debug=yes}} &00000078901234561234567.890.123.456,12345700
{{nts|890123456.12345678|debug=yes}} &0000000890123456123456890.123.456,12345680
{{nts|90123456.12345678|debug=yes}} &000000009012345612345690.123.456,12345678
{{nts|0123456.12345678|debug=yes}} &00000000001234561234560.123.456,12345678
{{nts|123456.12345678|debug=yes}} &0000000000123456123456123.456,12345678
{{nts|23456.12345678|debug=yes}} &000000000002345612345623.456,12345678
{{nts|3456.12345678|debug=yes}} &00000000000034561234563.456,12345678
{{nts|456.12345678|debug=yes}} &0000000000000456123456456,12345678
{{nts|56.12345678|debug=yes}} &000000000000005612345656,12345678
{{nts|6.12345678|debug=yes}} &00000000000000061234566,12345678
{{nts|.12345678|debug=yes}} &0000000000000000123456,12345678
{{nts|0.12345678|debug=yes}} &00000000000000001234560,12345678
{{nts|0.02345678|debug=yes}} &00000000000000000234560,02345678
{{nts|0.00345678|debug=yes}} &00000000000000000034560,00345678
{{nts|0.00045678|debug=yes}} &00000000000000000004560,00045678
{{nts|0.00005678|debug=yes}} &00000000000000000000560,00005678
{{nts|0.00000678|debug=yes}} &00000000000000000000060,00000678
{{nts|0.00000078|debug=yes}} &00000000000000000000000,00000078
{{nts|0.00000008|debug=yes}} &00000000000000000000000,00000008
{{nts|.00000008|debug=yes}} &0000000000000000000000,00000008
{{nts|0|debug=yes}} &00000000000000000000000

Xem thêm[sửa mã nguồn]

  • {{Ntsh}} - same as this template, but does not display (hides) the number
  • {{val}} - displays numbers and quantities with various formatting options
  • {{Convert}} - has a sortable option
  • {{Dts}} - for sorting dates
  • {{Sort}}
  • {{Hidden sort key}}