Template talk:Convert/Archive February 2019

Latest comment: 5 years ago by Johnuniq in topic Mark rounding in output?


Return hidden sortkey only?

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 → 7000139999999999999♠. (Maybe use {{formatnum|R}}). -DePiep (talk) 07:26, 1 February 2019 (UTC)

Mark rounding in output?

{{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)