Jump to content

Template talk:Percentage

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
(Redirected from Module talk:Percentage/doc)

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)[reply]

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

/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)[reply]

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)[reply]
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)[reply]
... 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)[reply]

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)[reply]

Why would you want to round to less than zero precision and what would that mean? --hydrox (talk) 04:58, 29 December 2013 (UTC)[reply]
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)[reply]

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)[reply]

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)[reply]
Thanks hydrox! Looks much better now. Cheers, Hwy43 (talk) 05:21, 29 December 2013 (UTC)[reply]
@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)[reply]
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)[reply]
@Hydrox: not sure how to find all the problematic uses, if there are any left. Frietjes (talk) 15:46, 8 January 2014 (UTC)[reply]
There's no way, but it's good to have that information available here anyway. --hydrox (talk) 15:57, 8 January 2014 (UTC)[reply]

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)[reply]

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

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)[reply]

Sanglahi86, try Template:Number and percent. Frietjes (talk) 19:46, 12 April 2016 (UTC)[reply]
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)[reply]

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)[reply]

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

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)[reply]

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)[reply]

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)[reply]
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)[reply]
Guarapiranga, it should work now. Frietjes (talk) 12:43, 19 October 2019 (UTC)[reply]
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 10−5. The error msg is: Error in Template:Nts: Fractions are not supported% Guarapiranga (talk) 20:13, 19 October 2019 (UTC)[reply]
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 10−5 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)[reply]
Cheers, Frietjes. Duly noted and documented. Guarapiranga (talk) 08:57, 21 October 2019 (UTC)[reply]

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)[reply]

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

Template-protected edit request on 6 December 2019

[edit]

Please add an option for no scientific notation. To do this, one may multiply the numerator by 10trunc(log denom – log numer) and add trunc(log denom – log numer) zeros to left on the decimal part at the end. Guarapiranga (talk) 20:36, 6 December 2019 (UTC)[reply]

 Not done: please make your requested changes to the template's sandbox first; see WP:TESTCASES. – Jonesey95 (talk) 02:16, 7 December 2019 (UTC)[reply]
see above, I said it would require more work. basically, we need to bypass the number formatting provided by Module:Math, or post-process it to remove the scientific notation. Frietjes (talk) 18:31, 7 December 2019 (UTC)[reply]
Took a stab at the latter here. Guarapiranga (talk) 21:52, 7 December 2019 (UTC)[reply]
Here's an use case for this change. Guarapiranga (talk) 22:17, 7 December 2019 (UTC)[reply]
Guarapiranga, thank you for the suggestion. I have implemented something similar in the module, see the examples. Frietjes (talk) 15:26, 8 December 2019 (UTC)[reply]
Excellent, Frietjes, thank you. Guarapiranga (talk) 15:28, 8 December 2019 (UTC)[reply]
Updated {{n+p}} accordingly. Cheers. Guarapiranga (talk) 15:35, 8 December 2019 (UTC)[reply]

Producing hyphen instead of negative sign

[edit]

I do not understand Lua or templates or what-have-you. Pictou County#Demographics contains figures which incorrectly use - in place of −. I am unable to fix the problem, because instead of just writing "-4.2%", which I could quickly and easily amend to read "−4.2%", an editor has helpfully typed in "{{percentage|{{#expr:43748-45643}}|45643|1}}". Great. Now only the keepers of the Lua can fix—or break—the typography. Please fix it. Regulov (talk) 19:44, 5 June 2021 (UTC)[reply]

Hey! Seriously! Code people!
You need to fix this! It should not be difficult to do!
The template should use a minus sign (−) rather than a hyphen (-) when output is negative. Regulov (talk) 14:54, 10 June 2022 (UTC)[reply]

Invisible padding

[edit]

It'd be interesting to add an option for invisible padding a la {{0}}, i.e. with <span style="visibility:hidden;color:transparent;">zeros</span>}}, to be used along with sigfig, where zeros indicates the number of decimal digits. This would align figures at the decimal point here, for instance. — 𝐆𝐮𝐚𝐫𝐚𝐩𝐢𝐫𝐚𝐧𝐠𝐚  11:13, 13 June 2021 (UTC)[reply]

This template put a hyphen where a minus sign belongs

[edit]

Currently the article titled Lloydminster says

The City of Lloydminster's 2015 municipal census counted a population of 31,377, a change of −0.3% from its 2013 municipal census population of 31,483.

Now contrast two versions below. I changed the former to the latter:

a change of -0.3% from

a change of −0.3% from

The former uses a hyphen and the latter a minus sign. The latter is required by WP:MOSMATH. The former came from this template, coded as {{percentage|{{#expr:31377-31483}}|31483|1}}. This template violates WP:MOSMATH and standard usage conventions. It should be edited to correct this problem. Michael Hardy (talk) 13:32, 1 October 2023 (UTC)[reply]

Request for optional + symbol for positive percentages

[edit]

Title says it all :-) The idea is that 33/100 becomes "+33%" rather than just "33%". Useful in tables/infoboxes where you have a mix of positive and negative percentages. Tompw (talk) 16:40, 24 October 2023 (UTC)[reply]

Adding substitution support

[edit]

I'm trying to add substitution support for this, which would help with e.g. {{AfC accept/B percentage}} (used in the {{AfC accept}} talk page message). However, doing so in the sandbox leads to results like {{subst:Percentage/sandbox|1|5|2}} = <span data-sort-value="7001200000000000000♠" style="display:none"></span>20%. This seems to be offering a more precise value than the displayed one, but the extra code is generally going to be unwanted. Is there a way to resolve this? Sdkbtalk 20:58, 3 October 2024 (UTC)[reply]