Pojdi na vsebino

Predloga:Sortiranje številčne tabele/dok

Iz Wikipedije, proste enciklopedije

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.

Purpose

[uredi kodo]

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

[uredi kodo]

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

Optional parameters
  • prefix: To display some text before the number, use |prefix=some prefix
    {{sšt|123456789,00123|prefix=approx. }}7008123456789001230approx. 123.456.789,00123
  • format: For unformatted output, use |format=no
    {{sšt|123456789,00123}}7008123456789001230123.456.789,00123
    {{sšt|123456789,00123|format=no}}7008123456789001230123456789.00123
  • debug: To display the sort key, use |debug=yes.
    {{sšt|123456789,00123|debug=yes}}7008123456789001230123.456.789,00123
    {{sšt|-123456789,00123|debug=yes}}2991876543210998770−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.

Sort key

[uredi kodo]

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.

Numbers within range
  • 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.
Numbers out of range
  • 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.

Limitations

[uredi kodo]
  • 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.

Examples

[uredi kodo]

{{sšt|123456789,00123}}7008123456789001230123.456.789,00123

For text which follows a number, {{sšt|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.

markup sortkey and number error spillover
{{sšt|debug=yes}}
{{sšt||debug=yes}}
{{sšt|between 2 and 3|debug=yes}} Napaka: between 2 and 3 To ni veljavno število. Prosimo, da o vnosih prebereš dokumentacijo {{Sortiranje številčne tabele}}.
{{sšt|10|prefix=approx.{{sp}}|debug=yes}} 7001100000000000000approx. 10
{{sšt|-5|debug=yes}} 2999500000000000000−5
{{sšt|-4|debug=yes}} 2999600000000000000−4
{{sšt|-73|debug=yes}} 2998270000000000000−73
{{sšt|-67|debug=yes}} 2998330000000000000−67
{{sšt|-20345678901234567,12345678|debug=yes}} 2983796543210987654−2,0345678901235×10^16
{{sšt|123,456e3|debug=yes}} 70051234560000000001,23456×10^5
{{sšt|123,456e2|debug=yes}} 70041234560000000001,23456×10^4
{{sšt|20345678901234567,12345678|debug=yes}} 701620345678901234520.345.678.901.234.570,00000000
{{sšt|100345678901234567,12345678|debug=yes}} 7017100345678901234100.345.678.901.234.560,00000000
{{sšt|1234567890123456,12345678|debug=yes}} 70151234567890123451.234.567.890.123.456,00000000
{{sšt|234567890123456,12345678|debug=yes}} 7014234567890123456234.567.890.123.456,12000000
{{sšt|34567890123456,12345678|debug=yes}} 701334567890123456134.567.890.123.456,12500000
{{sšt|4567890123456,12345678|debug=yes}} 70124567890123456124.567.890.123.456,12300000
{{sšt|567890123456,12345678|debug=yes}} 7011567890123456123567.890.123.456,12340000
{{sšt|67890123456,12345678|debug=yes}} 701067890123456123467.890.123.456,12346000
{{sšt|7890123456,12345678|debug=yes}} 70097890123456123457.890.123.456,12345700
{{sšt|890123456,12345678|debug=yes}} 7008890123456123456890.123.456,12345680
{{sšt|90123456,12345678|debug=yes}} 700790123456123456790.123.456,12345678
{{sšt|0123456,12345678|debug=yes}} 70051234561234567800.123.456,12345678
{{sšt|123456,12345678|debug=yes}} 7005123456123456780123.456,12345678
{{sšt|23456,12345678|debug=yes}} 700423456123456779923.456,12345678
{{sšt|3456,12345678|debug=yes}} 70033456123456780003.456,12345678
{{sšt|456,12345678|debug=yes}} 7002456123456780000456,12345678
{{sšt|56,12345678|debug=yes}} 700156123456780000056,12345678
{{sšt|6,12345678|debug=yes}} 70006123456780000006,12345678
{{sšt|,12345678|debug=yes}} 6999123456780000000,12345678
{{sšt|0,12345678|debug=yes}} 69991234567800000000,12345678
{{sšt|0,02345678|debug=yes}} 69982345678000000000,02345678
{{sšt|0,00345678|debug=yes}} 69973456780000000000,00345678
{{sšt|0,00045678|debug=yes}} 69964567800000000000,00045678
{{sšt|0,00005678|debug=yes}} 69955678000000000000,00005678
{{sšt|0,00000678|debug=yes}} 69946780000000000000,00000678
{{sšt|0,00000078|debug=yes}} 69937800000000000000,00000078
{{sšt|0,00000008|debug=yes}} 69928000000000000000,00000008
{{sšt|,00000008|debug=yes}} 6992800000000000000,00000008
{{sšt|0|debug=yes}} 50000000000000000000

See also

[uredi kodo]
  • {{Ntc}} - creates a center aligned sortable numeric table cell
  • {{Ntl}} - creates a left aligned sortable numeric table cell
  • {{Ntr}} - creates a right aligned sortable numeric table cell
  • {{Sšts}} - same as this template, but does not display (hides) the number
  • {{Ntsc}} - for converted units, sorts by the first number
  • {{Ntss}} - same as Sšt, but allows for the number to be scaled
  • {{Convert}} - has a sortable option
  • {{Dts}} - for sorting dates
  • {{Sms}}