Template talk:Percentage

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

Move template[edit]

{{editprotected}} Please move this template to Template:Percentage (which currently redirects here). It's common practice to spell out template names so that they are easy to read and understand what they are used for, and then have other names redirect to the template that are shorter to type. If you move this page, don't forget to move subpages. Gary King (talk · scripts) 01:17, 14 July 2010 (UTC)

That makes sense.  Done — Martin (MSGJ · talk) 08:43, 14 July 2010 (UTC)

/core[edit]

I can't really see the purpose of having this subtemplate. In the edit summary you say "for use without percentage sign" but it would probably be easier to use a parameter to switch off the percentage sign rather than calling a separate template. I put some possible code in the /sandbox. — Martin (MSGJ · talk) 08:44, 14 July 2010 (UTC)

I was thinking that /core could be used in other templates, especially those related to business where an increase from 100 to 200 would be a 100% increase, not a 200% increase as this template would report. Gary King (talk · scripts) 18:20, 14 July 2010 (UTC)
Wouldn't be easier just to rewrite the code? Each level get us closer to the template limits (probably not a really huge concern but the code is so simple). We could use the code {{#expr:100*{{{1|0}}}/{{{2|100}}} round ({{{3|0}}}>=0)*{{{3|0}}}}}{{{%|%}}} and the % parameter would let us control how to write it {{percentage|80|300|%= percent}} would give "27 percent", {{percentage|80|300|%=}} would give "27" and {{percentage|80|300}}, the default, would give "27%". JIMp talk·cont 18:17, 14 September 2011 (UTC)
... Just thinking ... I joined this discussion over a year after the last comment. If the subpage were going to be used in the way Gary suggests, it should probably already be used like this now. Is it? Is the subpage being used directly from elsewhere? Let's find out. JIMp talk·cont 01:13, 15 September 2011 (UTC)

Rounding to a negative precision[edit]

If we set parameter 3 to a negative, the template overrides this and uses zero instead. Why? JIMp talk·cont 18:19, 14 September 2011 (UTC)

Why would you want to round to less than zero precision and what would that mean? --hydrox (talk) 04:58, 29 December 2013 (UTC)
It probably means that e.g. {{Percentage | 1 | 3 | -1 }} yields 30%, i.e., a multiple of 10%. Gap9551 (talk) 13:50, 3 April 2017 (UTC)

Negative percentages... minus sign vs. ndash[edit]

The negative symbols between this template and {{PGR}} are different. I believe this simply uses the minus key on keyboards, whereas I believe the latter uses an ndash. Can we make the minus symbols consistent between the two templates? I believe this one should be made consistent with {{PGR}} and {{nts}}. See Alberta municipal censuses, 2013#Municipal census results where the inconsistency really sticks out. Hwy43 (talk) 22:53, 28 December 2013 (UTC)

It seems to use the unicode minus sign, which at least on my PC is somewhere between mdash and ndash in width. I think it's pretty obvious this template too should use the unicode minus sign. I was able to get this effect by wrapping the whole numeric part of this template in {{nts}}. Hope this does not break anything.. --hydrox (talk) 04:55, 29 December 2013 (UTC)
Thanks hydrox! Looks much better now. Cheers, Hwy43 (talk) 05:21, 29 December 2013 (UTC)
@Hydrox: and that screwed up Template:Seven Sisters, but now fixed by using {{#expr:}} instead (see here), so probably not a big deal. Frietjes (talk) 01:23, 8 January 2014 (UTC)
After the change, {{percentage}} now returns an HTML <span> element. That navbox was using the output as a CSS parameter, which was unanticipated. In case there are more uses of {{percentage}} in CSS expressions, or similar contexts where plain numeric value is desired, I have created {{percentage CSS}} as a drop-in replacement (i.e. changing {{percentage|...}} to {{percentage CSS|...}} should fix issues) --hydrox (talk) 06:43, 8 January 2014 (UTC)
@Hydrox: not sure how to find all the problematic uses, if there are any left. Frietjes (talk) 15:46, 8 January 2014 (UTC)
There's no way, but it's good to have that information available here anyway. --hydrox (talk) 15:57, 8 January 2014 (UTC)

formatnum:[edit]

Please use the parser function {{formatnum: NUMBER | R}} in the template (example), otherwise cases such as {{percentage | {{NUMBEROFACTIVEUSERS}} | {{NUMBEROFUSERS}}}} will not work. --Horcrux92 (talk) 08:57, 4 November 2015 (UTC)

Horcrux92, done. Frietjes (talk) 19:17, 20 November 2015 (UTC)

Automatically display the numerator and percentage in separate table cells.[edit]

In a table, there should be a parameter to automatically display the numerator in one cell and the percentage in the other (just like what {{convert}} template does using the disp=table parameter). It should look like the table below (on which the template was manually placed in one cell and the numerator in another).

Municipality Population
%
Allen 23,738 4%
Las Navas 36,539 6.2%

— Preceding unsigned comment added by Sanglahi86 (talkcontribs) 05:41, 17 March 2016 (UTC)

Sanglahi86, try Template:Number and percent. Frietjes (talk) 19:46, 12 April 2016 (UTC)
Thank you very much for creating that template (along with a very informative documentation). It is exactly what is needed for tables. Sanglahi86 (talk) 11:59, 13 April 2016 (UTC)

Word "percent"?[edit]

Hello. Is there an option to display the word percent instead of the symbol %? If yes, what is the format to use? Thanks. Sanglahi86 (talk) 09:34, 10 October 2016 (UTC)

Sanglahi86, yes, it was not documented. now see the last example. Frietjes (talk) 15:17, 1 May 2017 (UTC)

Significant figure[edit]

Is there an option to set significant figure precision (as in Template:sigfig) rather than number of decimal places? — Guarapiranga (talk) 08:31, 15 October 2019 (UTC)

Template-protected edit request on 18 October 2019[edit]

Pls add a |sigfig= option such as the one in Template:Convert (and in Template:Sigfig, of course). Guarapiranga (talk) 06:43, 18 October 2019 (UTC)

This edit request template is for well-formed, detailed changes that can be implemented by any editor who is familiar enough with template code to make the change. This suggestion for a change to this template will require some development and testing. You might want to post a request for help at WP:VPT. – Jonesey95 (talk) 16:13, 18 October 2019 (UTC)
Thanks, Jonesey95, will do. Perhaps the text in the edit request form needs to be updated to say that. Currently it says: State UNAMBIGUOUSLY your suggested changes below this line, preferably in a "change X to Y" format. Guarapiranga (talk) 21:50, 18 October 2019 (UTC)
Guarapiranga, it should work now. Frietjes (talk) 12:43, 19 October 2019 (UTC)
Thanks, Frietjes. I found it does work (e.g. here: List of countries and dependencies by population), except when the resulting percentage is smaller than 105. The error msg is: Error in Template:Nts: Fractions are not supported% Guarapiranga (talk) 20:13, 19 October 2019 (UTC)
Guarapiranga, I fixed it so it won't show an error in those cases, but you can see why it issued an error. when numbers are less than 105 the {{significant figures}} template uses scientific notation, which is not supported by {{ntsh}}. if we want to add the flexibility to not have the numbers formatted in this way, it will require some more work. Frietjes (talk) 12:40, 20 October 2019 (UTC)
Cheers, Frietjes. Duly noted and documented. Guarapiranga (talk) 08:57, 21 October 2019 (UTC)

New lua version[edit]

I have rewritten the template to use LUA which should be more efficient and allow for more flexibility in terms of output formatting. if you find a problem, please let me know so we can fix it and add that case to the testcases. thank you. Frietjes (talk) 14:43, 20 October 2019 (UTC)

No problems yet, Frietjes. Will that allow us to bypass the scientific notation? Guarapiranga (talk) 09:00, 21 October 2019 (UTC)