Template talk:Convert

From Wikipedia, the free encyclopedia
Jump to: navigation, 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 Help:Convert.
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: Help:Convert units.
For more, see the FAQ.

For the Lua module see the Module:Convert.
Convert tagged articles are in Category:Convert error categories
For earlier technical talks, see Technical archives.


The symbol for kilowatt-hour should be written as a product: "kW·h", instead of "kWh", which contradicts SI and NIST rules (and even WP:UNIT). — Mikhail Ryazanov (talk) 08:19, 28 July 2014 (UTC)

Outside Wikipedia, "kWh" is often used, so editors have a choice:
  • {{convert|123|kWh|abbr=on}} → 123 kWh (440 MJ)
  • {{convert|123|kW.h|abbr=on}} → 123 kW·h (440 MJ)
Johnuniq (talk) 09:37, 28 July 2014 (UTC)
I'm complaining about the opposite direction (MJ → kW·h). — Mikhail Ryazanov (talk) 10:01, 28 July 2014 (UTC)
What about:
  • {{convert|440|MJ|kW.h|abbr=on}} → 440 MJ (120 kW·h)
Is there a specific convert that is a problem? As you say, "kW·h" is correct, but Kilowatt hour asserts 'The symbol "kWh" is most commonly used in commercial, educational, scientific and media publications' which is why convert behaves as it does. Johnuniq (talk) 11:10, 28 July 2014 (UTC)
I suppose that the default behavior of WP templates should follow the WP rules, which require "kW·h". ;–)
(The sentence about "most commonly used" is rather strange. Was it supposed to mean "Commercial, educational, scientific and media publications most commonly use the symbol "kWh". However, ..."? Because otherwise, what are the publications that are not "commercial, educational, scientific and media"? But even in that case it looks like WP:OR, drawing this conclusion from a small number of examples that actually contradict the accepted standards.)
Mikhail Ryazanov (talk) 11:24, 28 July 2014 (UTC)

────────────────────────────────────────────────────────────────────────────────────────────────────I don't have a strong opinion on what convert should do for kWh, although I support the view that Wikipedia should follow the real world rather than lead it. The only discussion I can find is at 2008 MOSNUM. In May 2014 there were 61 converts using kWh in 36 articles, plus a couple of related units—for example, Electric car includes the correct:

  • {{convert|11|kWh/100 km|abbr=on}} → 11 kW·h/100 km (0.40 MJ/km; 0.18 kW·h/mi)
  • {{convert|21.25|kWh/100 km|abbr=on}} → 21.25 kW·h/100 km (0.765 MJ/km; 0.3420 kW·h/mi)

In May, no converts in articles used kW.h. One approach might be for me to post a list of the 36 articles containing kWh, then someone could change them to use kW.h. Something more permanent would need yet another MOS discussion, I think (WT:DATE). Johnuniq (talk) 02:27, 29 July 2014 (UTC)

Thanks for pointing at the old discussion. As I understood, only one person was advocating "kWh", whereas all other were for standard-compliance and consistency. Since our MOS already has a general rule (conforming to the standards), I do not think that introduction of exceptions for commonly misused notation is required or desirable. (I do not actually know how common in the real word this misuse is. But I know that many people say "degrees Kelvin" instead of "kelvins", which does not mean that we must make the same error here.) — Mikhail Ryazanov (talk) 05:45, 29 July 2014 (UTC)
I didn't investigate the history, but the take-home message from that discussion is that someone edited WP:MOSNUM to say kW·h should be used (or some other variation), however, that text has been replaced with mention of other units which absolutely must have a middle dot to make any sense. Correct or not, "kWh" is very commonly used outside Wikipedia. Planning for the convert template has always taken the view that while MOS is vital, editors should be in charge. To put it another way, I would not support changing what kWh does without a wider discussion—certainly more than our comments. Johnuniq (talk) 06:20, 29 July 2014 (UTC)
OK. Would you start the discussion? — Mikhail Ryazanov (talk) 06:46, 29 July 2014 (UTC)
Done, I have posted at WT:Manual of Style/Dates and numbers#Kilowatt-hour. Johnuniq (talk) 07:35, 29 July 2014 (UTC)
Thanks! — Mikhail Ryazanov (talk) 07:41, 29 July 2014 (UTC)

Scientific notation[edit]

Is there any way to force both input and output figures to be displayed in scientific notation, preferably tied to a specified significant figure using sigfig? Something like {{convert|93000|mph|km/h|sci=on|sigfig=4}} --> 9.300 × 104 miles per hour (1.497 × 105 km/h). This would be very useful in the astronomy articles I'm currently working in. I looked in the code and the module seems capable of something like this based on the documentation, but Lua is beyond me. Huntster (t @ c) 03:08, 7 August 2014 (UTC)

Scientific notation is automatically used if the value is very big or very small (value >= 1×109 or value < 1×10−4). There is no way to specify that scientific notation be used. Engineering notation is available for nearly all units, but the only available exponents are 3, 6, 9, 12, and 15, and it has a quirk: it uses words if abbreviations are off. A little more information is at Help:Convert units#Engineering notation. Here are examples (e6km/h is probably not the correct choice here, but I used it to show some variety):
  • {{convert|93.00|e3mph|e6km/h|sigfig=4}} → 93.00 thousand miles per hour (0.1497×10^6 km/h)
  • {{convert|93.00|e3mph|e6km/h|sigfig=4|abbr=on}} → 93.00×10^3 mph (0.1497×10^6 km/h)
That might help a little? Johnuniq (talk) 03:46, 7 August 2014 (UTC)
Unfortunately no, the articles would need more flexibility than that, as the scientific notation used in them always uses a single digit to the left of the decimal point. But thanks for the response. Huntster (t @ c) 14:19, 7 August 2014 (UTC)
As you saw, the module is pretty big and ugly. Frankly I wasn't really sure that all that code would run (Scribunto was brand new when I started in September 2012), and I mostly did the minimum to emulate the previously used set of templates. Therefore, the code is not as modular as it should be, and making it "proper code" would bloat it out quite a lot, extending it's complexity. What I'm trying to say is that there is no code to format the input number (it's only the converted outputs which can be in scientific notation if very small or large). I could look at what would be involved in adding something, but I'm on a bit of break from convert coding and wouldn't do anything quickly. Meanwhile, it would help if you could show a couple of articles where such features would be useful. Johnuniq (talk) 11:19, 8 August 2014 (UTC)


In the second paragraph of Quagga, {{convert}} produces the text

"4 ft 1 in–4 ft 5 in". Per WP:ENDASH this should read
"4 ft 1 in – 4 ft 5 in" (with a spaced en dash)

because dashes in ranges should be spaced "when at least one endpoint of the range includes at least one space" (in this case both endpoints include three spaces). The problem doesn't seem to be easily fixable (putting spaces around the dash in the template has no effect and putting non-breaking spaces around it produces an error), but it's very possible there's some intricacy in this template that I've missed. Any thoughts? – Arms & Hearts (talk) 14:00, 13 August 2014 (UTC)

  • Let's change MOS:ENDASH for this. End of problem. -DePiep (talk) 21:24, 13 August 2014 (UTC)
  • Question: how did you produce that outcome by {{convert}}? (as it is now, it is hard-code entered)-DePiep (talk) 21:29, 13 August 2014 (UTC)
  • What about {{convert|1-2|m|ft}} →
1–2 metres (3.3–6.6 ft) (spaces in this too) -DePiep (talk) 21:29, 13 August 2014 (UTC)

I guess A&H is correct that a spaced en dash would be better with output multiples like ftin. The quick fix is to use "to" instead. Examples of current behavior:

  1. {{convert|1|-|2|m|ft}} → 1–2 metres (3.3–6.6 ft) {{convert|1|-|2|m|ftin}} 1–2 metres (3 ft 3 in–6 ft 7 in)
  2. {{convert|125|-|135|cm|ftin|abbr=on}} → 125–135 cm (4 ft 1 in–4 ft 5 in)
  3. {{convert|125|to|135|cm|ftin|abbr=on}} → 125 to 135 cm (4 ft 1 in to 4 ft 5 in)

Result 1 is good—the dash is saying the range is from 1 to 2, and the unit is not part of that so the space before the unit is not relevant. Result 2 is not good because there are spaces in the output range. Result 3 shows the workaround. I'll think about how much overhead would be involved in having the module automatically add a space because it looks like there are over 80 such converts in articles. That won't be fast. Johnuniq (talk) 02:56, 14 August 2014 (UTC)

Using "to" in place of the dash is a sensible workaround I hadn't considered. – Arms & Hearts (talk) 16:44, 16 August 2014 (UTC)

New volume[edit]

For Track ballast#Quantities {{convert|1700|cuyd/mi|m3/km|abbr=on}} 1,700 cu yd/mi (810 m3/km) Peter Horn User talk 01:57, 16 August 2014 (UTC)

Done; that should work now. Johnuniq (talk) 03:01, 16 August 2014 (UTC)
Thanks a million. Peter Horn User talk 00:40, 17 August 2014 (UTC)

abbr=off or abbr=none[edit]

{{convert/spell|1/2|m|in|abbr=off}}, one-half metre (20 in) or {{convert/spell|1/2|m|in|abbr=none}} one-half metre (20 in). abbr=off or abbr=none do not work here with "convert/spell". Peter Horn User talk 00:53, 17 August 2014 (UTC)

Perhaps even better one-half metre (twenty inches). Peter Horn User talk 01:04, 17 August 2014 (UTC)
Yikes, we might have to delete {{convert/spell}} as a reminder that it should not be used (see April).
  • {{convert|1/2|m|in|spell=in}} → one-half metre (20 in)
  • {{convert|1/2|m|in|abbr=none|spell=in}} → one-half metre (20 inches)
  • {{convert|1/2|m|in|abbr=off|spell=in}} → one-half metre (20 inches)
  • {{convert|1/2|m|in|abbr=on|spell=in}} → one-half m (20 in)
  • {{convert|1/2|m|in|0|abbr=off|spell=on}} → one-half metre (twenty inches)
Johnuniq (talk) 01:17, 17 August 2014 (UTC)
{{convert/spell}} is in many articles and thus replacing it systimatically would be a hassle. Again, thanks. Peter Horn User talk 02:57, 17 August 2014 (UTC)
Removed the old template from 29 articles. Remaining: in 47 talkpages etc. Using in mainspace will splash the page with a warning.
────────────────────────────────────────────────────────────────────────────────────────────────────In short: for most cases {{convert|...|spell=in}} will do. (Other options: |spell=In, |spell=on, |spell=On). -DePiep (talk) 12:50, 17 August 2014 (UTC)
Thanks! That looked straightforward and yet solves the problem perfectly. I had never heard of {{main other}}, and coupling it with {{error}} gives a great result. Johnuniq (talk) 23:51, 17 August 2014 (UTC)


Template is missing Ampere-hour / Electric charge units. SkywalkerPL (talk) 11:01, 17 August 2014 (UTC)

The full list of units includes A.h, but there's not much to convert it to. Examples:
  • {{convert|2|A.h|coulomb}} → 2 ampere-hours (7,200 C)
  • {{convert|2|A.h|coulomb|abbr=on}} → 2 A·h (7,200 C)
  • {{convert|2|A.h|coulomb|abbr=off}} → 2 ampere-hours (7,200 coulombs)
Johnuniq (talk) 11:50, 17 August 2014 (UTC)
Oh... so how come I can't find it in documentation? Do CTRL+F and search for Ampere or Ah or A.h - can't find anything. SkywalkerPL (talk) 10:37, 18 August 2014 (UTC)
There are 1100 units so it's not really possible to list them all on the documentation visible at Template:Convert. That documentation includes "See also: complete Convert/list of units" and I just added a link at that list to the really full list that I mentioned above. Another way to find that is with the "See Help:Convert for up-to-date and more complete information" note at the top—that page links to a units page which also links to the full list. Any ideas on improving the docs are welcome. Johnuniq (talk) 12:26, 18 August 2014 (UTC)

More Protection[edit]

I asked for more protection [1]. Reasoning:

Full protection please. Current is TE level (with 650k transc's). I request this for self-protection (I have TE access). I am editing heavily in the support pages: /doc, subpages, examples, old versions. This could easily lead to a save-by-mistake (throwing 650k pages in the WP:JQ, and not bug-free knowing me). While we are at it and for the very same reason, one could protect Module:Convert (edit|talk|history|links|watch|logs) and its /data subpages (but not module:Convert/extra).

-DePiep (talk) 19:47, 17 August 2014 (UTC)


As provided on https://en.wikipedia.org/wiki/Tatami#Size , "In Japan, the size of a room is often measured by the number of tatami mats (-畳 -jō), about 1.653 square meters (for a standard (Nagoya) size tatami)." , can the unit be added to the conversion?C933103 (talk) 15:16, 21 August 2014 (UTC)

I don't see how a template would help much at that article because it's hard to improve on:

the size of a room is often measured by the number of tatami mats (-畳 -jō), about 1.653 square meters

Are many other articles saying things like "the room has an area of 6 mats (9.9 m2)"?
What would be the symbol (if abbr=on) and the name (if abbr=off)? Is there a "standard" mat size, and what is the exact conversion factor? Is there a reference for that? Johnuniq (talk) 03:40, 22 August 2014 (UTC)
Notes to consider: the article says "Shops were traditionally designed to be 5 1⁄2 mats, and tea rooms are frequently 4 1⁄2 mats." So if this is correct and existing parlance (more so in Japanese I guess; could be historical or in architectural profession), it is a usage (can C933103 read jawiki and expand?). A second note is that, would this be added, the datapage is growing into its secondary (I think) usefulness: an encyclopedia of convertable units. A base, well sourced, for content. For this, high usage is not needed. -DePiep (talk) 10:20, 22 August 2014 (UTC)
I also understand that it has a aspect ratio defined (2:1). This makes a secondary property, like golden ratio. We could think of converting a "from 1=0.91 m mat into 1 m mat" by this ratio.
Then Tatami#Size says that there are regional size differences (0.91 m, 0.955 m) for the "1", with one (Nagoya) being "formal" somehow. All have the 2:1 ratio. -DePiep (talk) 10:28, 22 August 2014 (UTC)