Template talk:Convert

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

Frequently asked questions (FAQ)
Q: When using {{convert}} why does the answer not seem right sometimes?
A: This template takes into account the precision of the supplied value and generally rounds the output to the same level of precision. If you need to change from the default output precision, see rounding.
Q: What are all the possible units (kg, lb, m, cm, ft, in, °C, °F, km, mi, nmi, mph, km/h, and so on)?
A: See units.
For more, see the FAQ.

Paragraph of the documentation for the Convert template[edit]

I received this on my talkpage. Quite a good question. Maybe someone else better rewrite the Rounding section? I think I myself am a bit blind for this.

Hi, DePiep! As near as I can tell from the page history, you are the editor who added the following text to the {{Convert}} template documentation under "Default rounding":

"If neither the desired precision nor the desired number of significant figures is specified, the conversion will be rounded either to precision comparable to that of the input value (the number of digits after the decimal point—or the negative of the number of non-significant zeroes before the point—is increased by one if the conversion is a multiplication by a number between 0.02 and 0.2, remains the same if the factor is between 0.2 and 2, is decreased by 1 if it is between 2 and 20, and so on) or to two significant figures, whichever is more precise. An exception to this is temperature, wherein the conversion will be rounded either to precision comparable to that of the input value or to that which would give three significant figures when expressed in kelvins, whichever is more precise."

I have read over this paragraph 4 or 5 times now, and still can't make sense of it (the em dashes are part of what is throwing me, along with how they are being used along with commas to indicate subsets of information about the template). I am not a mathematician, just an editor, but am wondering if you would be willing to rephrase that so that other editors like me can figure out what it means! It appears to be grammatically correct— I am not trying to correct you! I am just saying, "I don't understand it the way it is written". I suspect I am not the first person with this problem. I tried fixing it by rewriting it myself, but got lost in the structure. Any chance you would consider it? Thanks! A loose noose (talk) 00:58, 12 January 2019 (UTC)

ping A loose noose. -DePiep (talk) 06:39, 12 January 2019 (UTC)
See this September 2015 discussion where I proposed an edit to simplify the documentation for rounding and precision. I think it was discussed somewhere else as well but I cannot find it. Johnuniq (talk) 07:05, 12 January 2019 (UTC)
Any opinions on the proposal at the link in my comment? The original discussion was sidetracked. Johnuniq (talk) 06:17, 15 January 2019 (UTC)

Conversion error Celsius to Fahrenheit[edit]

The calculation to convert Celsius to Fahrenheit is C-temp * 1.8 + 32. However the template is not adding 32. For example, 15C converts to 59F, i.e., 15 * 1.8 + 32 = 59. However the template says 15 °C (27 °F), i.e. 15 * 1.8 = 27. Can someone fix this? EncyclopediaUpdaticus (talk) 16:49, 20 January 2019 (UTC)

Hard to believe that after all of this time, the basic F/C conversion done by this template is wrong. I think that you are confused:
{{convert|15|C|F}} → 15 °C (59 °F)
a change of 15C from 15C would be 30C or
{{convert|30|C|F}} → 30 °C (86 °F)
the example that you claim to be wrong is correct:
{{convert|15|C-change|0}} → 15 °C (27 °F)
59F + 27F = 86F = 30C
Trappist the monk (talk) 17:05, 20 January 2019 (UTC)
  • (ec)Rewrite the examples:
15C converts to 59F, i.e., 15 * 1.8 + 32 = 59. However the template says
{{convert|15|C-change|0}} → 15 °C (27 °F), i.e. 15 * 1.8 = 27.
Reply: proper input for these conversion expected:
{{convert|15|C|0}} → 15 °C (59 °F)
In temperature, there are two forms that can be converted. One is from scale to scale: x ° on the C scale converts to y ° on the F-scale. These are single number (value) temperatures, for example in the weather and in chemistry and cooking point of water (100 °C (212 °F)). Parameters to use: C, F.
Then there is a change of temperature. That is: on the C-scale, the temperature rises q degrees. How much is that rise on the F-scale? :Example: from water 90 °C to boiling water 100 °C (that is: plus 10 °C):
{{convert|15|–|35|C-change|F-change}}{{convert|10|C-change|F-change|0}} → 10 °C (18 °F). Parameters to use: C-change, F-change.
Check: 90 °C (194 °F) rises to 100 °C (212 °F): C rises 10 °, F rises 18 ° Green tickY.
HTH. -DePiep (talk) 17:08, 20 January 2019 (UTC)
OK, so I am looking at an article Symplocarpus foetidus which uses the convert template as: {{convert|15|–|35|C-change|F-change}} which results in 15–35 °C (27–63 °F). A range is specified here but the doc is unclear for the range format. How should it be coded? EncyclopediaUpdaticus (talk) 17:39, 20 January 2019 (UTC)
I think it is correct as coded:
Eastern skunk cabbage is notable for its ability to generate temperatures of up to {{convert|15|–|35|C-change|F-change}} above air temperature...
Eastern skunk cabbage is notable for its ability to generate temperatures of up to 15–35 °C (27–63 °F) above air temperature... (emphasis added)
so if air temp is 20C, the plant can generate temperatures of 20 + 15 = 35C to 20 + 35C = 55C above air temp
{{convert|20|C|F}} → 20 °C (68 °F)
{{convert|35|C|F}} → 35 °C (95 °F)
{{convert|55|C|F}} → 55 °C (131 °F)
95°F − 68°F = 27°F
131°F − 68°F = 63°F
Trappist the monk (talk) 17:57, 20 January 2019 (UTC)
(ec) re EncyclopediaUpdaticus Yes a tricky situation! The wording "range" in there means something different (not a temperature change really). To be used is, and {{Convert}} supplies this: "range from value A to value B" (both are values on a single temperature scale). The article already does so wrt mm-inches: "40–55 cm (15.5–21.5 in)". For the temperatures:
{{convert|15|–|35|C|F}} → 15–35 °C (59–95 °F) (it is a range on the C-scale, not a change on the C-scale)
Done [1] -DePiep (talk) 18:05, 20 January 2019 (UTC)
@DePiep: no, the Symplocarpus foetidus example is a range of changes, not a range of actual temperatures. Read the text carefully; it's saying that the plant can raise (i.e. change) its temperature above ambient. Peter coxhead (talk) 21:08, 20 January 2019 (UTC)
Peter coxhead Wow, yes, indeed. It reads:
"Eastern skunk cabbage is notable for its ability to generate temperatures of up to 15–35 °C above air temperature" (italics added; no conversion yet).
So yes: when air temp is say 25 °C, it raises (changes) upwards for 15 to 35 ° (i.e., upwards to 40–60 °C). That truly is a change not a range for {{Convert}}.
This implies, we do have to use |C-change, F-change= here, as the article (now correctly) does. In C and F, the temperature raises by 15–35 °C (27–63 °F).
This also implies that the OP was wrong wrt this article (the OP example is correct: temp does raise with 27 °F etc.).
late signing: DePiep (talk) 14:09, 31 January 2019 (UTC)

Return hidden sortkey only?[edit]

Convert can add a table sortkey like this:

{{convert|10|m|ft|sortable=on}} → <span style="display:none">7001100000000000000</span>10 metres (33&nbsp;ft); shows like: 10 metres (33 ft)

Is it possible to have the key returned, but nothing else (no visible text)?

I'd like to use that in a table, so I can manipulate the actual visible value while having the right sortkey in there. Or should I go to Lua and approach the module? (could not find this in {{Val}} either). -DePiep (talk) 14:16, 31 January 2019 (UTC)

Solved otherwise. Situation has same unit everywhere, so I can use {{ntsh}}. No need to go to basic SI units (no prefixes). -DePiep (talk) 16:10, 31 January 2019 (UTC)
I don't think convert can help with that. Johnuniq (talk) 22:55, 31 January 2019 (UTC)
String templates and modules can be applied to the output of templates but it often has to rely on the formatting of the output and may fail after changes. Using Module:String#match: {{#invoke:String|match|s={{convert|10|m|ft|sortable=on}}| pattern=<span.*span>}} selects the span with the sortkey and discards the rest. According to Special:ExpandTemplates, {{convert|10|m|ft|sortable=on}} currently produces <span style="display:none" class="sortkey">7001100000000000000♠</span>10 metres (33 ft) and not what Template:Convert#Sorting claims. With my code it produces <span style="display:none" class="sortkey">7001100000000000000♠</span>. Don't try this directly in articles. If it's done with a template then there is only one place to fix if it starts to fail. I don't know a current template which does it. PrimeHunter (talk) 03:10, 1 February 2019 (UTC)
or: first {{Convert}} to basic SI unit(s) (no prefixes), also set |disp=number to get output number only, then feed that number into {{ntsh}}:
{{convert|5|km/h|m/s|disp=number}} → 1.4 → 7000140000000099999♠. (Maybe use {{formatnum|R}}). -DePiep (talk) 07:26, 1 February 2019 (UTC)

Mark rounding in output?[edit]

{{convert|1852|m|ft}}‬ gives: 1,852 metres (6,076 ft), with the correct number of significant figures. Is there a template parameter that would give: 1,852 metres (≈6076 ft). Maybe this isn't necessary? Is there any WP policy requiring indication of rounding? I came across this in article about the linear unit the nautical mile, where the exact conversions might be of interest. --Cornellier (talk) 00:01, 15 February 2019 (UTC)

Convert might not be suitable for some special situations and I wouldn't worry about having hard-coded values in the article. However, it is possible to match the text currently displayed:
  • {{convert|1,852|m|ft mi|disp=x| (approximately |)}} → 1,852 metres (approximately 6,076 ft; 1.151 mi)
Johnuniq (talk) 02:54, 15 February 2019 (UTC)