Wikipedia:Advanced Convert coding Information & Wikipedia:Advanced Convert coding Links at HealthHaven.com
advertise
add site
services
publishers
database
health videos
Bookmark and Share

search wiki for    ?
web dir firms image gallery news pdf wiki shop video 
about
toolbar
stats
live show
health store
more stuff
JOIN/LOGIN
Featured Results:
Tubal Reversal Information on Wikipedia
Tubal Reversal Information on Wikipedia
tubal-reversal.net
 Keeping Wikipedia Spick and Span
Keeping Wikipedia Spick and Span
fightaging.org
 Society for Neuroscience - Neuroscience Wikipedia Initiative
Society for Neuroscience - Neuroscience Wikipedia Initiative
sfn.org
 Doctor Eugene Lipov, M.D. - Biography and Wikipedia Entry
Doctor Eugene Lipov, M.D. - Biography and Wikipedia Entry
eugenelipovmd.org
 

This essay, Wikipedia:Advanced Convert coding, describes some techniques to improve or expand the use of the Wikipedia unit-converter, Template:Convert. Most of the tips involve setting the parameters.

Some techniques here are beyond the basics described in the Convert docpage ("{{Convert/doc}}") which explains almost all basic options of the parameters, also showing examples of each. The currently supported units are listed under {{Convert/list of units}}.

Contents

[edit] Other abbreviation options: abbr=in or abbr=out

29-Oct-09: There are options now to control the input versus the output-abbreviations (similar to linking as options lk=in or lk=out). There are now 5 settings for abbreviation:

  • abbr=off, abbr=on, abbr=in, abbr=out & abbr=none.

This is the first time it has been possible to abbreviate just the input units, using abbr=in, and leave full-word form as the output: such as "xx km (xx miles)":

{{convert|16|cm|in|abbr=in}}   gives: 16 cm (6.3 inches)
{{convert|4|kg|lb|abbr=in}}       gives: 4 kg (8.8 pounds)
{{convert|6|ft|3|in|cm}}                 gives: 6 feet 3 inches (191 cm)
{{convert|6|ft|7|in|cm|abbr=in}}      gives: 6 ft 7 in (201 centimetres)

For many conversions, the default has been "abbr=out" so that the km/mi conversions have stated "xx kilometres (xx mi)". The other options (in/out) were added for completeness, to allow anything: in, out, both or none. However, the logical preference seems to be abbr=in, because for most articles where the culture is metric, then "km" would be obvious, but other readers might wonder about "mi". The use of abbr=in gives "xx km (xx miles)" and also avoids the end-spelling of -metre/meter which has been irritating to some readers. Anyway, this is the first time for users to have a choice of abbreviating just the input unit-names.

[edit] Rounding the output amounts

When invoking {{convert}}, the end-parameter can be a number to designate the level of rounding, such as "0" for whole numbers, "1" for 1 decimal, "2" for 2 decimals, "-2" for whole hundreds, etc. For example:

  • {{convert|741|ft |0}}   gives: 741 feet (226 m)
  • {{convert|741|ft |1}}   gives: 741 feet (225.9 m)
  • {{convert|741|ft |2}}   gives: 741 feet (225.86 m)
  • {{convert|741|ft |-2}}  gives: 741 feet (200 m)

The use of the rounding-parameter can be altered by using sigfig=3 (or similar) to control the precision of the output amounts.

[edit] Surrounding conversions to round by 5

04-Nov-2009: In some instances, a converted result should be rounded to the nearest 5 units, rather than the nearest 1 unit. For now, this can be done by using a math-expression outside a conversion. The algorithm is:  round5 = (n/5 round 0) * 5. For example, in metres-to-feet:

  • Precise:  80.0 metres (262.467 ft) and 93.0 metres (305.118 ft)
  • Round 80 m, {{#expr:({{convert|80|m|ft|3|disp=output number only}}/5 round 0)*5}} for: 260 ft
  • Round 93 m, {{#expr:({{convert|93|m|ft|3|disp=output number only}}/5 round 0)*5}} for: 305 ft

In general, for any number rounded to the nearest 5:

  • Rounding 13.11 by 5: {{#expr: (13.11/5 round 0) * 5}} gives: 15
  • Rounding 19.44 by 5: {{#expr: (19.44/5 round 0) * 5}} gives: 20
  • Rounding 32.48 by 5: {{#expr: (32.48/5 round 0) * 5}} gives: 30
  • Rounding 32.51 by 5: {{#expr: (32.51/5 round 0) * 5}} gives: 35

Larger numbers will require removing commas by {{formatnum: 1,234|R}}:

  • Round 967 m, {{#expr:({{formatnum: {{convert|967|m|ft|3|disp=output number only}}|R}}/5 round 0)*5}} for: 3175 ft

Although the need to round by 5's is rare, similar coding can be used to adjust the results in other ways.

[edit] Suppressing commas

04-Nov-2009: To suppress commas, use option "abbr=comma" to abbreviate (remove) commas from the display. So, the results would be as follows:

  • {{convert|2500|m|ft|abbr=comma}}    gives: 2500 metres (8200 ft)
  • {{convert|1426|C|F}}                       gives: 1,426 °C (2,599 °F)
  • {{convert|1426|C|F|abbr=comma}}   gives: 1426 °C (2599 °F)
  • {{convert|3500|F|C}}                       gives: 3,500 °F (1,930 °C)
  • {{convert|3500|F|C|abbr=comma}}   gives: 3500 °F (1930 °C)

The option "abbr=comma" can also be used when comma is the separator ("disp=comma") to simplify the results: 3500 °F, 1930 °C.

[edit] Customizing the results with output-only

The template {{convert}} has parameters to alter the display-format, such as abbr=on to abbreviate all units, or disp=comma to use a comma-separator. However, there might be a need for a customized display, beyond the formats offered as parameters. For maximum customization, use the options to show only the results:

  • disp=output only -  display only the results with units
  • disp=output number only -  display only the resulting numbers (no units)

By using those options, all the surrounding text can be customized, with any words or wikilinks, as needed. For example, use:

Single values:
  • {{convert|742|ft |disp=output only}}              gives: 226 m
  • {{convert|747|ft |disp=output only}}              gives: 228 m
  • {{convert|742|ft |disp=output number only}}   gives: 226
Ranges:
  • {{convert|742|to|747|ft |disp=or}}                gives: 742 to 747 feet or 226 to 228 metres
  • {{convert|742|to|747|ft |disp=output only}}   gives: 226 to 228 m
  • {{convert|28|to|31|C |F |disp=output only}}      gives: 82 to 88 °F

Then, the surrounding text can be any wording:

"a 28-to-31 °C temperature range (equivalent 82 to 88 °F) is possible"

With that customization, any extra words can be inserted, such as "equivalent" or "range" or "temperature" (etc.) to surround the result (of "82 to 88 °F").

[edit] Displaying result first by disp=flip

10-Nov-2009: The display option disp=flip can be used to flip the result as first in order:
           {{convert|36|ft|6|in |m|abbr=on|disp=flip}}      gives: 11.13 m (36 ft 6 in)
           {{convert|12|lb|8|oz |kg|abbr=on|disp=flip}}   gives: 5.7 kg (12 lb 8 oz)
           {{convert|10|m|ft|abbr=on|disp=flip}}   gives: 33 ft (10 m)

So, the option "disp=flip" will flip the order of the output, putting the result as first in the text and the input unit as last.

[edit] Displaying unit name by disp=unit

The display type disp=unit will display just the unit name (as singular, plural or hyphenated) for an input-unit symbol:

  • {{convert|1 |ft|disp=unit}}           gives: foot
  • {{convert|9 |ft|disp=unit}}           gives: feet
  • {{convert|7 |m3|disp=unit|abbr=on}}       gives: m3
  • {{convert|7 |m3|disp=unit|abbr=off}}       gives: cubic metres
  • {{convert|1 |cuyd|disp=unit|lk=on}}       gives: cubic yard
  • {{convert|1 |cuyd|disp=unit|adj=on}}      gives: cubic-yard

The option disp=unit can also be used, during article writing, as a means to display a unit name or symbol for a specific unit-code when writing an article.

[edit] Template:Convert/3 for cubic or 3 amounts

06-Nov-2009: The subtemplate Template:Convert/3, for 3-amount conversions, allows any mixture of "to" or "by" or "x" or "-" or "and" (etc.) as the range-words; plus the separator can also be a semicolon, using disp=semi:

  • {{convert/3 |5|by|6|by|7|m|ft}}     gives: 5 by 6 by 7 metres (16 by 20 by 23 ft)
  • {{convert/3 |5|x|6|x|7|m|ft}}        gives: 5×6×7 metres (16×20×23 ft)
  • {{convert/3 |7|to|8|to|9|km|mi|abbr=on}}    gives: 7 to 8 to 9 km (4.3 to 5.0 to 5.6 mi)
  • {{convert/3 |7|to|8|to|9|km|mi|adj=on}}      gives: 7-to-8-to-9-kilometre (4.3-to-5.0-to-5.6-mi)
  • {{convert/3 |5|to|6|by|7|m|ft}}     gives: 5 to 6 by 7 metres (16 to 20 by 23 ft)
  • {{convert/3 |5|by|6|x|7|m|ft}}      gives: 5 by 6×7 metres (16 by 20×23 ft)
  • {{convert/3 |11|-|22|-|33|°C|F|disp=semi|lk=on}}     gives: 11–22–33 °C; 52–72–91 °F

The input units (like "metre") can be abbreviated or linked, using parameters abbr=in, abbr=on, lk=on or lk=in.

[edit] Convert/date gives ISO date or day for: date

08-Nov-2009: The unit name "date" triggers the new (huge) subtemplate {{Convert/date}} to convert a date into ISO format or the day-of-the-year:

  • {{convert|8 November|date|day}}       gives: 8 November (day 312)
  • {{convert|Nov 19|date|ISO}}             gives: Nov 19 (ISO date 11-19)
  • {{convert|April 31|date|ISO}}            gives: April 31 (ISO date
    Convert/date: Unknown date "April 31" in {{Convert|April 31||ISO...}}.)

That template was purposely designed (to be gigantic) to show that Wikipedia's MediaWiki preprocessor can handle at least 2,928 switch-branches in a single subtemplate, plus internal documentation and category-links. See page: Template:Convert/date.

[edit] Convert/wrench handles spanner wrench sizes

31-Oct-2009: Another smart-conversion template, as {{Convert/wrench}} and {{Convert/spanner}}, can display the related wrench (spanner) sizes. For sizes that don't quite fit, it displays the term "(loose 3/4)" or "(loose 1/8)" (etc.) because sometimes, bolts have odd sizes (or outer deposits) that allow a loose wrench to fit. Some examples:

  • {{convert|3/4|wrench|mm}}              gives:   3/4 inch spanner (19 mm)
  • {{convert|1/8|wrench|mm}}              gives:   1/8 inch spanner (3 mm)
  • {{convert|17|wrench|inch}}              gives:   17 mm spanner (loose 11/16 inch)
  • {{convert|22|wrench|inch|sp=us}}    gives:   22 mm wrench (7/8 inch)

The template lists from 1-26mm so far, in #switch-blocks, but allows adding other official sizes. (When the size is 1mm less, it displays "loose 17/16" etc.) It handles most common sizes, putting 26mm as a "1-inch" size. Anyway, Template:Convert/wrench is another example of the next-generation smart templates.

[edit] Convert/note gives pitch for piano key: note

08-Nov-2009: The unit name "note" triggers the new subtemplate {{Convert/note}} to convert a piano key note-name into the equivalent pitch (frequency) in hertz:

  • {{convert|middle C|note}}       gives: middle C  (pitch 261.626 hertz)
  • {{convert|A-440|note}}           gives: A-440  (pitch 440.000 hertz)
  • {{convert|f#|note}}                 gives: f#  (pitch 184.997 hertz)

That template was developed to also demonstrate the use of non-numeric conversions, converting a name into a musical pitch (frequency). See page: Template:Convert/note.

[edit] Plan to reduce subtemplates

08-Nov-2009: It is becoming far more difficult to implement new options, as the number of Convert-subtemplates grows by hundreds each time. Recently, over 650 new subtemplates were added, but we should prepare to reduce those in the next few months. See essay: "Wikipedia:A plan to reduce Convert subtemplates". It would be easier to control commas by: comma=off, comma=in, comma=out, comma=on. Plus, some people want to round the input amount, such as round=in, round=out (current default), or round=on. Unless the current design is condensed, those new options could require modifying hundreds of subtemplates.

[edit] Category for recent Convert subtemplates

Before October 2009, the talk-page Template_talk:Convert had been the only notice of new Convert subtemplates. However, the "Category:2009 Convert unit subtemplates" is a separate category for newer subtemplates. It can be listed, to see new subtemplate names. Insert that category-link at the bottom of new templates.

[edit] Defining new conversion subtemplates

Just like with creating new article-pages, users are allowed to create new unit-conversion subtemplates. For example, someone might want to use "kilograms-per-centimetre" (kg/cm) as a variation of the typical per-metre conversion (using "kg/m"):

 Template:Convert/kg/m {{convert/{{{d}}}|{{{1}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|s={{{s|}}} | r={{{r}}} | u=kg/m | n=kilogram per met{{{r}}} | h=kilogram-per-met{{{r}}} | l=kilograms per met{{{r}}} | t=linear density | o=lb/yd | b=1 | j=0-{{{j|0}}}<!--end-->}} 

The new subtemplate would be named "Template:Convert/kg/cm" with the coding copied and altered from viewing the template {{Convert/kg/m}}:

 Template:Convert/kg/cm {{convert/{{{d}}}|{{{1}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|s={{{s|}}} | r={{{r}}} | u=kg/cm | n=kilogram per centimet{{{r}}} | h=kilogram-per-centimet{{{r}}} | l=kilograms per centimet{{{r}}} | t=linear density | o=lb/yd | b=100 | j=0-{{{j|0}}}<!--end-->}} 

Note that the new conversion factor is b=100, as the multiplier from kg/m to kg/cm, based on 1 m = 100 cm.  When editing a conversion-subtemplate, be very careful to match the exact nesting of braces (pairing the "{{{ }}}"); otherwise, the parameters might be treated as literal text and listed across the page instead (such as string of "...| t=linear density | o=lb/yd | b=100...").

The numbered parameters, {{{1}}}, {{{2}}}, {{{3}}} & {{{4}}}, are the first 4 positional parameters passed from using: {{convert|{1}|{2}|{3}|{4}|...}}.

The other parameters are:

  • u = unit symbol, n = unit name, l = plural unit name (lowercase L),
  • h = hyphenated name (singular, such as: mile-per-gallon)
  • t = text linked (such as article "Miles per gallon" for "mpg")
  • b = conversion factor relative to base units (base = 1 m)
  • j = conversion-precision (putting "5" shows result as 5 digits)
  • s = combined rounding for sigfig=x plus end-parameter "0" etc.
  • r = end-spelling as either r=er (American) or r=re
  • y = unit-code for 4-part unit names (view: {{Convert/mpgus}})

Using the new template {{Convert/kg/cm}}, the result would be:

  • {{Convert|9|kg/m|kg/cm}}          gives: 9 kilograms per metre (0.090 kg/cm)
  • {{Convert|4|kg/m|kg/cm}}          gives: 4 kilograms per metre (0.040 kg/cm)
  • {{Convert|7.3|kg/m|kg/cm}}       gives: 7.3 kilograms per metre (0.073 kg/cm)
  • {{Convert|7.4|kg/m|kg/cm|5}}    gives: 7.4 kilograms per metre (0.07400 kg/cm)
Re-converting:
  • {{Convert|0.09|kg/cm|kg/m}}          gives: 0.09 kilograms per centimetre (9.0 kg/m)
  • {{Convert|0.15|kg/cm|kg/m}}          gives: 0.15 kilograms per centimetre (15 kg/m)
  • {{Convert|18|kg/cm|kg/m|adj=on}}   gives: 18-kilogram-per-centimetre (1,800 kg/m)

There is no limit to the number of conversion-subtemplates that can be created. Again, when editing, be very careful to match the nested-braces (pairing "{{{" and "}}}"). Each unit-conversion subtemplate is really the coding to invoke another subtemplate (typically invoking {{Convert/LoffAoffDbSoff}} for output), so that is the reason why the pairing of braces is critical.

[edit] Defining new display-subtemplates

With the option-name parts of subtemplate naming, an option value could be added to quickly connect to a particular variation subtemplate, but there would be hundreds of total variations. For example, using abbr=xyz, the related custom variations can be coded as more than 800 subtemplates named with option-name part "Axyz". However, in general, when a variation is created, only a few dozen of the possible combinations are implemented, and the remaining hundreds are omitted, as future subtemplates "under construction" to complete the particular option.

For option abbr=xyz, the 800 subtemplates would be named as follows:

  • regular units with "( )": Template:Convert/LoffAxyzDbSoff, /LoffAxyzDbSon, /LonAxyzDbSoff, /LonAxyzDbSon,
    /LinAxyzDbSoff, /LinAxyzDbSon, /LoutAxyzDbSoff, /LoutAxyzDbSon, etc.
  • regular units with slash "/": Template:Convert/LoffAxyzDsSoff, /LoffAxyzDsSon, /LonAxyzDsSoff, /LonAxyzDsSon,
    /LinAxyzDsSoff, /LinAxyzDsSon, /LoutAxyzDsSoff, /LoutAxyzDsSon, etc.
  • regular units with "or": Template:Convert/LoffAxyzDorSoff, /LoffAxyzDorSon, /LonAxyzDorSoff, /LonAxyzDorSon,
    /LinAxyzDorSoff, /LinAxyzDorSon, /LoutAxyzDorSoff, /LoutAxyzDorSon, etc.
(...and 24 similar, with Dcomma, D/, Doutput only...)
  • 2-unit groups with "( )": Template:Convert/LoffAxyzDbSoff2, /LoffAxyzDbSon2, /LonAxyzDbSoff2, /LonAxyzDbSon2,
    /LinAxyzDbSoff2, /LinAxyzDbSon2, /LoutAxyzDbSoff2, /LoutAxyzDbSon2, etc.
  • 2-unit groups with slash "/": Template:Convert/LoffAxyzDsSoff2, /LoffAxyzDsSon2, /LonAxyzDsSoff2, /LonAxyzDsSon2,
    /LinAxyzDsSoff2, /LinAxyzDsSon2, /LoutAxyzDsSoff2, /LoutAxyzDsSon2, etc.
  • 2-unit groups with "or": Template:Convert/LoffAxyzDorSoff2, /LoffAxyzDorSon2, /LonAxyzDorSoff2, /LonAxyzDorSon2,
    /LinAxyzDorSoff2, /LinAxyzDorSon2, /LoutAxyzDorSoff2, /LoutAxyzDorSon2, etc.
(...and 24 similar, with Dcomma, D/, Doutput only...)
  • temperature units with "( )": Template:Convert/LoffAxyzDbSoffT, /LoffAxyzDbSonT, /LonAxyzDbSoffT, /LonAxyzDbSonT,
    /LinAxyzDbSoffT, /LinAxyzDbSonT, /LoutAxyzDbSoffT, /LoutAxyzDbSonT, etc.
  • temperature units with slash "/": Template:Convert/LoffAxyzDsSoffT, /LoffAxyzDsSonT, /LonAxyzDsSoffT, /LonAxyzDsSonT,
    /LinAxyzDsSoffT, /LinAxyzDsSonT, /LoutAxyzDsSoffT, /LoutAxyzDsSonT, etc.
  • temperature units with "or": Template:Convert/LoffAxyzDorSoffT, /LoffAxyzDorSonT, /LonAxyzDorSoffT, /LonAxyzDorSonT,
    /LinAxyzDorSoffT, /LinAxyzDorSonT, /LoutAxyzDorSoffT, /LoutAxyzDorSonT, etc.
(...and 24 similar, with Dcomma, D/, Doutput only...)
  • regular unit-ranges with "( )": Template:Convert/Dual/LoffAxyzDbSoff, /Dual/LoffAxyzDbSon, /Dual/LonAxyzDbSoff,
    /Dual/LonAxyzDbSon, /Dual/LinAxyzDbSoff, /Dual/LinAxyzDbSon,
    /Dual/LoutAxyzDbSoff, /Dual/LoutAxyzDbSon.
(...and 40 similar, with Ds, Dor, Dcomma, D/, Doutput only...)
  • 2-unit-ranges with "( )": Template:Convert/Dual/LoffAxyzDbSoff2, /Dual/LoffAxyzDbSon2, /Dual/LonAxyzDbSoff2,
    /Dual/LonAxyzDbSon2, /Dual/LinAxyzDbSoff2, /Dual/LinAxyzDbSon2,
    /Dual/LoutAxyzDbSoff2, /Dual/LoutAxyzDbSon2.
(...and 40 similar, with Ds, Dor, Dcomma, D/, Doutput only...)
  • temperature unit-ranges with "( )": Template:Convert/Dual/LoffAxyzDbSoffT, /Dual/LoffAxyzDbSonT, /Dual/LonAxyzDbSoffT,
    /Dual/LonAxyzDbSonT, /Dual/LinAxyzDbSoffT, /Dual/LinAxyzDbSonT,
    /Dual/LoutAxyzDbSoffT, /Dual/LoutAxyzDbSonT.
(...and 40 similar, with Ds, Dor, Dcomma, D/, Doutput only...)
  • (...and 100 for 2-unit results, with Ds, Dor, Dcomma, D/,...)
  • (...and 100 for imperial-units, with Ds, Dor, Dcomma, D/,...)
  • (...and 100 for USre-units, with Ds, Dor, Dcomma, D/,...)
  • (...and 100 for USer-units, with Ds, Dor, Dcomma, D/,...)
  • (...and 100 for engineering-units, with Ds, Dor, Dcomma, D/,...)

Due to the vast number of subtemplates, many of the possible combinations are omitted, which could appear as missing templates, someday, when those combinations are selected by a user on a rare occasion.

[edit] See also

 
[ This essay is a draft to be expanded later. ]



Product Results (view all...)

search wiki for    ?
web dir firms image gallery news pdf wiki shop video 



↑ top of page ↑about thumbshots