| advertise add site services publishers database health videos | ![]() | about toolbar stats live show health store more stuff JOIN/LOGIN |
coding books, medical code books, coding manuals, hcpcs coding guides,... zhealthpublishing.com |
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}}. [edit] Other abbreviation options: abbr=in or abbr=out29-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:
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)":
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 amountsWhen 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:
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 504-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:
In general, for any number rounded to the nearest 5:
Larger numbers will require removing commas by {{formatnum: 1,234|R}}:
Although the need to round by 5's is rare, similar coding can be used to adjust the results in other ways. [edit] Suppressing commas04-Nov-2009: To suppress commas, use option "abbr=comma" to abbreviate (remove) commas from the display. So, the results would be as follows:
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-onlyThe 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:
By using those options, all the surrounding text can be customized, with any words or wikilinks, as needed. For example, use:
Then, the surrounding text can be any wording:
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=flip10-Nov-2009: The display option disp=flip can be used to flip the result as first in order: 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=unitThe display type disp=unit will display just the unit name (as singular, plural or hyphenated) for an input-unit symbol:
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 amounts06-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:
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: date08-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:
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 sizes31-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:
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: note08-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:
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 subtemplates08-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 subtemplatesBefore 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 subtemplatesJust 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:
Using the new template {{Convert/kg/cm}}, the result would be:
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-subtemplatesWith 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:
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
|
| ↑ top of page ↑ | about thumbshots |