Template talk:Number table sorting


 * Note. Adding  to the relevant column header solves many numerical sorting problems. See Help:Sorting.

Template talk:Sort
Centralized discussion for all issues surrounding sortkeys for wikitables created here: Template talk:Sort. ~ trialsanderrors 09:02, 5 April 2007 (UTC)

Bizarre interaction with age template
See Village pump (technical). —Steve Summit (talk) 01:25, 29 November 2008 (UTC)

Indian numbering system
I am trying to translate this template for an Indian language which uses the Indian numbering system. Anyone has an idea how to modify this template for that?

Thanks Abhijit Sathe (talk) 21:43, 13 July 2009 (UTC)

Edit request from 134.253.26.6, 15 November 2010
Many pages would like to use this template with a non-numeric prefix, e.g. a less-than sign or a greater-than sign (see List of European capital cities by area). One option is to just use sort for the entire table, but it would be helpful if we could add a prefix option to this template. To do this, change &lt;/span&gt;0}} to &lt;/span&gt;0}}, which will insert the optional prefix between the "no display" and actual display parts. Thanks! 134.253.26.6 (talk) 16:57, 15 November 2010 (UTC)


 * That seems sensible and fairly uncontroversial, so done. Please could you update the documentation? &mdash; Martin (MSGJ · talk) 17:10, 15 November 2010 (UTC)
 * Documentation updated. Thank you. 134.253.26.6 (talk) 18:03, 15 November 2010 (UTC)

Requested edit: Making number formatting optional
I'm making some edits to a large table containing lots of dates and find the  magic word is causing commas in the years, which looks odd.

I've just updated the sandbox with a new argument   that will optionally suppress that   call. Could someone effect that edit to the template itself, please?

The specifics of the edit are changing 0}} to }} , the rest of the template is merely a copy/paste of the current revision. Thanks! — OwenBlacker (Talk) 15:52, 16 April 2011 (UTC)
 * Wouldn't it be more logical to use no instead of yes? Obviously the default would be "yes" in this case. &mdash; Martin (MSGJ · talk) 16:50, 17 April 2011 (UTC)
 * I don't really have any strong preference; I'd not really thought about it either way. I've created a template ntsy that's waiting for this edit, but that's easy enough to change. — OwenBlacker (Talk) 21:41, 17 April 2011 (UTC)
 * ✅. Please let me know if this does not work correctly. &mdash; Martin (MSGJ · talk) 12:26, 18 April 2011 (UTC)
 * Perfect, thank you. — OwenBlacker (Talk) 12:34, 24 April 2011 (UTC)

Proposed fix for negative numbers
I going take more time to proof my fix. I ran across situations where #expr: choked on comma delimited numbers. I seems like this does not happen in the current version. So ignore the following for now. Currently the code in the sandbox works.

This template generates output that facilitates the sorting of numeric values in sortable tables. Currently the template fails to generate output that allows negative numbers to be sorted correctly. I have a version that fixes this in the template's sandbox and some test cases here. The sandbox version includes more conditionals and generates a longer hidden sort key. If you think it might break some pages then maybe the template should be forked.&#32;– droll  &#91;chat&#93;  22:24, 23 August 2011 (UTC)
 * I'm happy to apply your code if you are sure it is working correctly. I don't see foresee any problems with this approach. &mdash; Martin (MSGJ · talk) 07:49, 29 August 2011 (UTC)


 * I'm confident that the code is good. My only concern is that it will use more resources and might break a page, but the page would have to have a lot of other stuff as well as tables.&#32;– droll  &#91;chat&#93;  09:23, 29 August 2011 (UTC)


 * P.S. I included a  parameter that can be used by the ntsh template. I'll clean up the documentation and propose that  become a front end for this template. Convert transcludes .&#32;– droll   &#91;chat&#93;  09:34, 29 August 2011 (UTC)
 * Okay, let me know when you are ready. Per WP:PERF I don't think you need to worry about performance issues. Do you mean quiet? And do you think we could expand the ntsh acronym by moving the template to a clearer name? &mdash; Martin (MSGJ · talk) 19:25, 29 August 2011 (UTC)


 * Your right the name of the parameter is . I added  template&#32;– droll   &#91;chat&#93;  03:57, 30 August 2011 (UTC)
 * Made a few tweaks to whitespace and deployed. Let me know if anything goes wrong! &mdash; Martin (MSGJ · talk) 08:58, 31 August 2011 (UTC)

Thanks, MSGJ.&#32;– droll  &#91;chat&#93;  10:23, 31 August 2011 (UTC)


 * I haven't dealt with this template in a while, but it seems like something else has changed. Before, I believe you could also put text in the argument and it would work fine. Now, something like produces the following:


 * With the PRE tag and all. Weird? I'm also getting tons of errors in another template that uses this template, and in the process of debugging it, hopefully it has nothing to do with the most recent edit, although I suspect it probably does since the arguments over there also include some text at the end. Gary King  ( talk  ·  scripts )  18:18, 10 October 2011 (UTC)


 * This page is a mess, at least on the browser I'm using right now (Firefox 3.6.6 Mac OS X). Something tells me that the new code supports numbers only, and no letters or symbols. I am going to use some ntsh until there is another solution in place. mechamind  9  0  20:30, 12 October 2011 (UTC)

Proposed edit: explicitly state how to use the template for following text
I was confused a bit by this article. It mentioned that the template is useful if text follows a number, but didn't specifically state how the template was supposed to be used in that situation. I figured it out, you simply type and put text after it to achieve that result. I would recommend that this be stated explicitly somehow. The wikitext " as of January 2012" achieves an output of "426,004 as of January 2012" but with the numerical sort key 426,004. Please state this in the article, I can't edit it myself. I believe it will be highly useful to others, and should only serve to make the article better. Thanks. Jessemv (talk) 05:04, 13 January 2012 (UTC)
 * Hi Jessemv, the documentation for this template is held at Template:Number table sorting/doc and this is fully editable by anyone, so please make the changes you see fit. Regards &mdash; Martin (MSGJ · talk) 14:39, 13 January 2012 (UTC)
 * Brilliant, I'll try my best. :) Jessemv (talk) 22:53, 13 January 2012 (UTC)

And now for something completely different ...
I was looking at this template wondering whether we could do the same thing quicker; whether the code could be simplified (look, for example at number table sorting/positive). Sure it could thought I and we could easily extend the range a bit whilst we're at it.

We're limitted to a range of ±1016 with a precision of 6 decimal places. Look at the hidden output. There's an "&" and twenty-three digits (unless it's out of range). The first digit is a "1" or "0" (for positive & negative), I thought, we could get five times the range by going all the way up to "9". The next sixteen digits are calculated one by one. This is inefficient. The final six digits are calculated altogether. This is better; so why not calculate those sixteen digits like that? And why not? So I got to work on a new design.

To cut a medium-length story short, it's just dawned on me that we're doing it all wrong. I'm planning to significantly simplify the code and at the same time vastly expand the range. I'm not talking five times the range anymore, not five hundred time nor even five million; more like five thousand octoquadragintillion. It's simple. Don't do the same thing quicker do something better & quicker. Instead of having the first digit represent the sign have the first four digits represent the sign and the order of magnitude. The next fourteen digits will represent the significand.

Instead of using zeros to show magnitude, use numbers. We'll be looking at a range of about ±10300 to ±10–300 instead of the current ±1016 to ±10–6. J IM ptalk·cont 08:00, 9 May 2012 (UTC)


 * Don't forget that Ntsh uses this template's sub-templates.&#32;– droll  &#91;chat&#93;  18:47, 9 May 2012 (UTC)

No, actually that's what lead me here in the first place. Well, I've written the new version. I'm afraid I haven't quite simplified the code. But I haven't significantly increased it either. There's about the same ammount of code as the current version (so I'm not expecting it to break anything). But what it does achieve is the promised increase in range. J IM ptalk·cont 01:52, 10 May 2012 (UTC)

Okay, four and a half months later I'm back to finish off the job. The new code has been tested and things look good. It going live. J IM ptalk·cont 01:16, 27 September 2012 (UTC)

Addition of a suffix parameter
There is a prefix parameter with this template, but would it be very difficult to add a suffix parameter? If this parameter was to be added, it would be like this:

would display: 10,000 (est.)

Would this be difficult to implement? Thanks. Dustin ( talk ) 18:39, 20 June 2014 (UTC)

Protected edit request on 22 September 2014
Template:Nts redirects to Template:Number table sorting. Surely the redirect should be tagged

 NickGibson3900 Talk 08:06, 22 September 2014 (UTC)
 * Yes check.svg Done -- Red rose64 (talk) 18:35, 22 September 2014 (UTC)

Sort key quirks
While checking Module:Val I have noticed many minor differences regarding sort keys. The issues probably do not affect table sort orders, but there is a problem in the template if anyone wants a challenge. I believe the val sort keys shown below (generated by the code at function  in Module:Convert/sandbox) are correct. Johnuniq (talk) 03:49, 28 July 2015 (UTC)

Didn't sort
I tried to use this template at List of household surveys in the United States, but it still doesn't sort correctly. Any ideas of how to solve this? Mikael Häggström (talk) 07:57, 2 November 2016 (UTC)
 * Do you mean the items in the "Number of people" column which start with "Over"? That's because the sort key occurs after "Over ", so the item is sorted as text starting with "O". One solution would be to use ntsh at the beginning to produce the key, followed with "Over 50,000" to produce the visible text. That requires duplicating the number. Another solution would be to use val like this:
 * Using  generates a space, and   makes "Over " a prefix that is displayed before the value, but after the hidden sort key. A difference is that val makes all the text "no wrap".
 * However, you cannot use val for all the items because it cannot handle "3.5 million" (it can only show numbers like $Over&amp;#32;50,000$). The sort keys produced by val and ntsh are almost always the same, so you could use val for some items and ntsh/nts for others. However, it might be simpler to use ntsh/nts for all entries and duplicate the values with "Over". Johnuniq (talk) 09:42, 2 November 2016 (UTC)
 * Thanks for identifying the problem! I switched Over___ to ___+. Mikael Häggström (talk) 08:08, 3 November 2016 (UTC)
 * Thanks for identifying the problem! I switched Over___ to ___+. Mikael Häggström (talk) 08:08, 3 November 2016 (UTC)

Precision parameter request
et al, I have embedded an expression template into this template and I want the output to round to a precision of two decimal places. Right now,  produces 3,177.6727 when I want it to produce 3,177.67. Can anyone assist by either adding a precision parameter within this or the expression template? Cheers, Hwy43 (talk) 03:26, 7 December 2016 (UTC)
 * @Hwy43: The template round can be used. However, since you are using #expr, it supports rounding. The syntax is a shock, but it works.
 * It would give ugly results if an error occurred in the calculation, and the sort key is based on the rounded value which is perhaps suboptimal. However, it should do what is needed. Johnuniq (talk) 04:02, 7 December 2016 (UTC)
 * , thanks. I've used the round template. Another question though...  renders 3,569.1, yet I want it to produce 3,569.10 (so that all entries within a column consistently have two decimal places). Is there a way to force a zero as the last decimal place? I'm having a similar problem with the percentage template. I want   to produce 99.0%, yet it renders 99%. Hwy43 (talk) 04:41, 7 December 2016 (UTC)
 * I think you would need some really ugly hacks to display trailing zeroes. Template syntax is not my strong point and you might ask at WP:WikiProject Templates. Hmm, I just found decimals which might help if used instead of round. Johnuniq (talk) 04:48, 7 December 2016 (UTC)
 * Decimals worked. See how  produces . Haven't been able to get it or rnd to force the trailing zero within percentage yet. I'll ask at Template talk:Percentage and if no luck I'll approach WP:WikiProject Templates as suggested. Hwy43 (talk) 06:51, 7 December 2016 (UTC)
 * Discovered the pad parameter at percentage.  now produces 99.0%. We may want to consider implementing a pad parameter here as well to avoid the ugly hack workarounds described above. Hwy43 (talk) 07:00, 7 December 2016 (UTC)
 * Discovered the pad parameter at percentage.  now produces 99.0%. We may want to consider implementing a pad parameter here as well to avoid the ugly hack workarounds described above. Hwy43 (talk) 07:00, 7 December 2016 (UTC)

Nts template in other templates
Can this be used in other templates? One user keeps adding it to Template:Player3. However, it breaks the table as - (hyphen), – (ndash) and — (mdash) can no longer be used there. – Sabbatino (talk) 22:41, 27 December 2016 (UTC)

Minor error in error message

 * The switch to the module has caused minor Linter errors when the variable  is empty. The error message looks like this:  . Note the two consecutive single quote marks, which the parser interprets as opening italic formatting. Can you please make a minor adjustment to insert a space between the two quote marks, or do something else to prevent this formatting error? Thanks. – Jonesey95 (talk) 10:39, 30 March 2019 (UTC)
 * , sure, ill fix it later today. —Th e DJ (talk • contribs) 13:41, 30 March 2019 (UTC)
 * Don't think thats new though... if i remember the testcase results correctly, it did that before as well... —Th e DJ (talk • contribs) 13:43, 30 March 2019 (UTC)
 * , ok, invalid input is now allowed —Th e DJ (talk • contribs) 12:37, 31 March 2019 (UTC)
 * Thanks, that seems to have cleared up the problem at Template:WDL/doc, for example. – Jonesey95 (talk) 19:14, 31 March 2019 (UTC)

NTS template modification

 * the recent modification is causing problems at 2019 Alberta municipal censuses. Historically I have coded in blank fields until the census results are published and it simply rendered as nothing. The old way was helpful because I didn't have to comment out the empty template previously (i.e.  ). Cheers, Hwy43 (talk) 21:38, 30 March 2019 (UTC)
 * , invalid input is now allowed. —Th e DJ (talk • contribs) 12:37, 31 March 2019 (UTC)
 * Thanks! Hwy43 (talk) 21:11, 1 April 2019 (UTC)

No scientific notation
List of legislatures by number of members looks rather silly with the populations of China and India in scientific notation. Is there a way to suppress this and use regular numbers? Or perhaps just converting everything to data-sort-type="number" would be better? Would have to figure out how to do that automatically instead of by hand... Reywas92Talk 05:22, 19 April 2019 (UTC)
 * It appears there is no way to disable that scientific notation display. If I ever had time I might fix that but meanwhile I put a kludge in the article to workaround the problem. Johnuniq (talk) 07:20, 19 April 2019 (UTC)
 * A fix for this would be great. List of mergers and acquisitions by Alphabet also looks silly with scientific notation. - Samuel Wiki (talk) 05:28, 7 June 2019 (UTC)

Requested move 31 May 2019

 * The following is a closed discussion of a requested move. Please do not modify it. Subsequent comments should be made in a new section on the talk page. Editors desiring to contest the closing decision should consider a move review after discussing it on the closer's talk page. No further edits should be made to this discussion. 

The result of the move request was: moved. There is a consensus for this requested move. (closed by non-admin page mover) qedk (t 桜 c) 19:44, 9 June 2019 (UTC)

– No apparent reason for the module to have an abbreviated name when the template's name has the abbreviation expanded. * Pppery * it has begun... 23:31, 31 May 2019 (UTC)
 * Module:Nts → Module:Number table sorting


 * Support - modules tend to follow the naming standards for templates, and the principle of "function should be clear from the template name" is a reasonable one. -- Netoholic @ 03:34, 1 June 2019 (UTC)
 * Support per above. Note though that Dts is at the abbreviated name, but I'd support its change as well. --Gonnym (talk) 08:36, 1 June 2019 (UTC)
 * My mistake. In that case, I am going to withdraw Module:Dts from this nomination and open a new one for both the template and the module because I feel that conflating "Rename module to match template" and "Expand abbreviation in template name" is more confusing than helpful. * Pppery * it has begun... 12:26, 1 June 2019 (UTC)
 * Template talk:Dts. * Pppery * it has begun... 12:31, 1 June 2019 (UTC)
 * Before I can make this change, can you tell me which templates are affected by this (as well as Module:Dts), ? Since modules can't have redirects, I cannot readily make the changes since templates will need to be edited as well. --qedk (t 桜 c) 19:33, 9 June 2019 (UTC)
 * Yeah, module moving is a mess like that. The trick I use to determine which templates use a module is to do search for . In this case, that search suggests that Number table sorting and Ntsh are the templates that need to be updated. * Pppery * it has begun...  19:37, 9 June 2019 (UTC)
 * Done now. I fixed a few in the documentation with bad regex, not sure if there's more. --qedk (t 桜 c) 19:44, 9 June 2019 (UTC)


 * The above discussion is preserved as an archive of a requested move. Please do not modify it. Subsequent comments should be made in a new section on this talk page or in a move review. No further edits should be made to this section.

Template-protected edit request on 8 December 2019
Please consider adding a text alignment option, defaulted to the right (e.g.: ). Guarapiranga (talk) 19:33, 8 December 2019 (UTC)
 * Red information icon with gradient background.svg Not done for now: please establish a consensus for this alteration before using the template. The same request at Template talk:Date table sorting was objected to. Cabayi (talk) 20:04, 8 December 2019 (UTC)
 * That's not an appropriate response,.
 * The page you're linking clearly states it is not one of Wikipedia's policies or guidelines.
 * The edit template-protected template itself does say anything about establishing a consensus before using its use. In fact, it says the very opposite:
 * The very WP:consensus page you're linking defines consensus as absence of objections. If there are no objections, there already is consensus. The appropriate response to this is to either say let's wait 48h and see if there are any objections, or simply waiting that time period before acting upon the request.
 * Guarapiranga (talk) 20:28, 8 December 2019 (UTC)
 * ❌ There's no reason to believe that wouldn't oppose this request as well; alignment has just as little to do with sorting numbers as sorting dates. * Pppery * it has begun...  21:03, 8 December 2019 (UTC)
 * Who's Gonnym?? What reason is there to believe that he would? Are we supposed to read his mind? And how's that relevant?? What matters to WP:consensus is whether anyone opposition (not whether someone would). Do you? Guarapiranga (talk) 21:08, 8 December 2019 (UTC)
 * Gonnym was the user who opposed Template talk:Date table sorting, which was linked by Cabayi above. The rest of your comment consists of speculation that proved to be false, rendering it moot. (And before you ask, notifying users who participated in related discussions does not constitute inappropriate canvassing). * Pppery * it has begun... 21:47, 8 December 2019 (UTC)
 * Hey,thanks for the mention. As I've commented on the previous request, what does alignment have to do with sorting? Oppose this request. Gonnym (talk) 21:19, 8 December 2019 (UTC)
 * Are you opposing adding alignment as an option on this template simply based on its name, ? Sortable numbers on a table are almost always right justified. Why not save editors some trouble, and have it as an option (defaulted to the right)? n+p does, why shouldn't nts? (and dts!) Guarapiranga (talk) 13:46, 10 December 2019 (UTC)
 * You can't really use the fact that template "x" does something, when you were the one changed it to do it just recently. I mainly oppose your proposal because it mixes two completely different functions. One is a simple behind the scene code that handles the sorting of a cel in a column. The other adds style to the cell. This could potentially lead to a lot of issues, major or small. Have you checked all transclusions to see how this template is used? Are you sure that this won't cause any issue? Also, you asked for it to be default right-aligned. Again, can you share your research on how many pages have set it to right-aligned compared to any other alignment? --Gonnym (talk) 14:07, 10 December 2019 (UTC)
 * It wasn't; built the option in from day 1 (check the history before pointing fingers, perhaps). Guarapiranga (talk) 14:15, 10 December 2019 (UTC)
 * My mistake, but unless you actually comment on something which is relevant and not nitpick a mistake I made, that doesn't change anything. --Gonnym (talk) 14:22, 10 December 2019 (UTC)
 * Gonnym has given excellent answers which indicate that the edit request should not proceed. Johnuniq (talk) 22:46, 10 December 2019 (UTC)
 * My mistake, but unless you actually comment on something which is relevant and not nitpick a mistake I made, that doesn't change anything. --Gonnym (talk) 14:22, 10 December 2019 (UTC)
 * Gonnym has given excellent answers which indicate that the edit request should not proceed. Johnuniq (talk) 22:46, 10 December 2019 (UTC)

how to put international number format or gaps into number?
tried to use format=gaps parameter to use gaps in the template, but it did not like it. when using international thousands separators like, or ٬ or arabic thousands separator ٬ the sorting does not work correctly. how would one do this? ThurnerRupert (talk) 01:10, 15 August 2023 (UTC)

ntsh
The docs for Template:Number table sorting hidden have a deprecation notice directing editors to use this template instead, but I don't see anything in the docs that make clear how one would achieve the same result. It looks to me like data-sort-value might be the better substitute? Walkersam (talk) 00:23, 20 April 2024 (UTC)
 * I don't have an answer to your point about the deprecation notice, but both templates use data-sort-value. The following shows input to Special:ExpandTemplates and the result: Johnuniq (talk) 01:01, 20 April 2024 (UTC)