Template:Convert: Difference between revisions

From The World of Gotha
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{#switch: {{{2}}}
<includeonly>{{#switch: {{lc:{{{2}}}}}
| km =   {{formatnum: {{{1}}} }} km ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} / 1.609 round {{{3|0}}} }} }} mi)
| km =   {{formatnum: {{{1}}} }} km ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} / 1.609 round {{{3|0}}} }} }} mi)
| mi =   {{formatnum: {{{1}}} }} mi ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} * 1.609 round {{{3|0}}} }} }} km)
| mi =   {{formatnum: {{{1}}} }} mi ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} * 1.609 round {{{3|0}}} }} }} km)
| m =   {{formatnum: {{{1}}} }} m ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} * 3.281 round {{{3|0}}} }} }} ft)
| m =     {{formatnum: {{{1}}} }} m ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} * 3.281 round {{{3|0}}} }} }} ft)
| ft =   {{formatnum: {{{1}}} }} ft ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} / 3.281 round {{{3|0}}} }} }} m)
| ft =   {{formatnum: {{{1}}} }} ft ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} / 3.281 round {{{3|0}}} }} }} m)
| yd =   {{formatnum: {{{1}}} }} yd ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} / 1.094 round {{{3|0}}} }} }} m)
| yd =   {{formatnum: {{{1}}} }} yd ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} / 1.094 round {{{3|0}}} }} }} m)
| kg =   {{formatnum: {{{1}}} }} kg ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} * 2.205 round {{{3|0}}} }} }} lb)
| cm =    {{formatnum: {{{1}}} }} cm ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} / 2.54 round {{{3|0}}} }} }} in)
| lb =   {{formatnum: {{{1}}} }} lb ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} / 2.205 round {{{3|0}}} }} }} kg)
| in cm = {{formatnum: {{{1}}} }} in ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} * 2.54 round {{{3|0}}} }} }} cm)
| km2 = {{formatnum: {{{1}}} }} km<sup>2</sup> ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} / 2.59 round {{{3|0}}} }} }} sq mi)
| mm =    {{formatnum: {{{1}}} }} mm ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} / 25.4 round {{{3|0}}} }} }} in)
| in =    {{formatnum: {{{1}}} }} in ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} * 25.4 round {{{3|0}}} }} }} mm)
| kg =   {{formatnum: {{{1}}} }} kg ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} * 2.205 round {{{3|0}}} }} }} lb)
| lb =   {{formatnum: {{{1}}} }} lb ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} / 2.205 round {{{3|0}}} }} }} kg)
| t =    {{formatnum: {{{1}}} }} t ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} * 1.102 round {{{3|0}}} }} }} ST)
| st =    {{formatnum: {{{1}}} }} ST ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} / 1.102 round {{{3|0}}} }} }} t)
| g =    {{formatnum: {{{1}}} }} g ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} / 28.35 round {{{3|0}}} }} }} oz)
| oz =    {{formatnum: {{{1}}} }} oz ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} * 28.35 round {{{3|0}}} }} }} g)
| km2 =   {{formatnum: {{{1}}} }} km<sup>2</sup> ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} / 2.59 round {{{3|0}}} }} }} sq mi)
| sq mi
| sq mi
| sqmi = {{formatnum: {{{1}}} }} sq mi ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} * 2.59 round {{{3|0}}} }} }} km<sup>2</sup>)
| sqmi = {{formatnum: {{{1}}} }} sq mi ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} * 2.59 round {{{3|0}}} }} }} km<sup>2</sup>)
| m2 =   {{formatnum: {{{1}}} }} m<sup>2</sup> ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} * 10.764 round {{{3|0}}} }} }} sq ft)
| m2 =   {{formatnum: {{{1}}} }} m<sup>2</sup> ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} * 10.764 round {{{3|0}}} }} }} sq ft)
| sq ft
| sq ft
| sqft = {{formatnum: {{{1}}} }} sq ft ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} / 10.764 round {{{3|0}} }} }} m<sup>2</sup>)
| sqft = {{formatnum: {{{1}}} }} sq ft ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} / 10.764 round {{{3|0}}} }} }} m<sup>2</sup>)
| km/h =  {{formatnum: {{{1}}} }} km/h ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} / 1.609 round {{{3|0}}} }} }} mph)
| mph =  {{formatnum: {{{1}}} }} mph ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} * 1.609 round {{{3|0}}} }} }} km/h)
| c =    {{formatnum: {{{1}}} }} °C ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} * 1.8 + 32 round {{{3|0}}} }} }} °F)
| f =    {{formatnum: {{{1}}} }} °F ({{formatnum: {{#expr: ({{formatnum:{{{1}}}|R}} - 32) / 1.8 round {{{3|0}}} }} }} °C)
| l =    {{formatnum: {{{1}}} }} l ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} / 3.785 round {{{3|0}}} }} }} gal)
| gal =  {{formatnum: {{{1}}} }} gal ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} * 3.785 round {{{3|0}}} }} }} l)
| ml =    {{formatnum: {{{1}}} }} ml ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} / 29.574 round {{{3|0}}} }} }} fl oz)
| fl oz
| floz =  {{formatnum: {{{1}}} }} fl oz ({{formatnum: {{#expr: {{formatnum:{{{1}}}|R}} * 29.574 round {{{3|0}}} }} }} ml)
| #default = <span id="uom" style="font-weight:bold; font-style:italic; color:#C51E3A;">Error: Unit of measure is not supported</span>
| #default = <span id="uom" style="font-weight:bold; font-style:italic; color:#C51E3A;">Error: Unit of measure is not supported</span>
}}
}}</includeonly><noinclude>{{doc}}[[Category:Templates]]</noinclude>

Latest revision as of 22:05, 24 September 2024

Template documentation
Shortcut
{{cvt}}

The {{convert}} template calculates the value of a measurement in one unit from the value of another unit and presents a formatted result. The result can be rounded.

Usage

  • Basic usage: {{convert|1|2}}
  • Full usage: {{convert|1|2|3}}

Parameters

Parameter Description Type Status Notes
1 Measurement value Numeric Required May be formatted or unformatted
2 Measurement unit String Required Use the unit code from supported units below
3 Rounding Numeric Optional Defaults to 0, the nearest integer. Setting a positive number adds decimal places. Setting a negative number rounds to the left of the decimal point (e.g., tens, hundreds, thousands, etc.).

Supported units

Type Unit Unit code Calculated unit Sample default result
Area square kilometer km2 square mile 10 km2 (4 sq mi)
square mile sqmi
sq mi
square kilometer 10 sq mi (26 km2)
square meter m2 square feet 10 m2 (108 sq ft)
square feet sqft
sq ft
square meter 10 sq ft (1 m2)
Length kilometer km mile 10 km (6 mi)
mile mi kilometer 10 mi (16 km)
meter m feet 10 m (33 ft)
feet ft meter 10 ft (3 m)
yard yd meter 10 yd (9 m)
centimeter cm inch 10 cm (4 in)
inch in cm centimeter 10 in (25 cm)
milimeter mm inch 100 mm (4 in)
inch in milimeter 10 in (254 mm)
Mass tonne (metric ton) t short ton (US ton) 10 t (11 ST)
short ton (US ton) st tonne (metric ton) 10 ST (9 t)
kilogram kg pound 10 kg (22 lb)
pound lb kilogram 10 lb (5 kg)
gram g ounce 100 g (4 oz)
ounce oz gram 10 oz (284 g)
Speed kilometers per hour km/h miles per hour 10 km/h (6 mph)
miles per hour mph kilometers per hour 10 mph (16 km/h)
Temperature celsius c farenheit 10 °C (50 °F)
farenheit f celsius 10 °F (−12 °C)
Volume liter l US gallon 10 l (3 gal)
US gallon gal liter 10 gal (38 l)
mililiter ml US fluid ounce 100 ml (3 fl oz)
US fluid ounce floz
fl oz
mililiter 10 fl oz (296 ml)

Examples

  • Default (rounded to nearest whole integer): {{convert|816|km}} → 816 km (507 mi)
  • Rounded to two decimal places: {{convert|15|m|2}} → 15 m (49.22 ft)
  • Rounded to hundreds: {{convert|626|m|-2}} → 626 m (2,100 ft)

Errors

  • Unsupported unit of measure: Error: Unit of measure is not supported. See the #supported units table for units the template can convert or check your measurement unit code to ensure it matches the code in the table. Note: The template will accept the unit code in either upper or lower case.
  • Non-numeric value for measurement or rounding: 5O1 km (Expression error: Unrecognised word "o". mi). Check your input to ensure th measurement value and rounding value are both numeric.