Author: qleah
Description:
A suggestion has been made on [[en:Wikipedia:Village pump]] to allow the
automatic conversion of measurements according to the user's preferences. There
are a number of ways this could be done; for convenience and by analogy to
automatic date conversion, I suggest that the measurement in question should be
enclosed in double brackets. Preference options should include SI, imperial, SI
(imperial), imperial (SI), "base" SI, and "no preference" (equivalent to SI
(imperial)).
Assuming a user prefers SI:
- [[1 ft]] renders as [[1 E-1 m|.3 m]]
- [[53 lb]] -> [[1 E1 kg|24 kg]]
- [[.0022 lb]] -> [[1 E-3 kg|1 g]]
- [[10 km]] -> [[1 E4 m|10 km]]
- [[1 apc]] -> [[1 E-2 m|3 cm]]
For SI (imperial), or if no preference has been set, or for anonymous users, the
SI measurement should be given with an appropriate Imperial measurement given in
parentheses:
- [[1 ft]] renders as [[1 E-1 m|.3 m]] (1 [[foot|ft]])
- [[53 lb]] -> [[1 E1 kg|24 kg]] (53 [[pound|lb]])
- [[.0022 lb]] -> [[1 E-3 kg|1 g]] (.035 [[ounce|oz]])
- [[10 km]] -> [[1 E4 m|10 km]] (6.2 [[mile|mi]])
- [[1 apc]] -> [[1 E-2 m|3 cm]] (1.2 [[inch|in]])
The rendered values should have at least two significant digits of precision, or
the originally used precision, whichever is larger.
The value should be stored internally as an SI measurement in the "base" units,
i.e. '''g''', '''m''', '''m²''', '''s''', '''J''', '''K''', etc.
Appropriate units for rendering may be chosen according to a table of orders of
magnitude and their associated units. Note that a separate table must be used
for each preference option.
SI preference:
{| |- ! >= !! < !! Units |- | 1 E-2 m || 1 E0 m || cm |- | 1 E0 m || 1 E3 m || m |- | 1 E3 m || ... || km |- |}
Imperial preference:
{| |- ! >= !! < !! Units |- | ... || 1 ft || in |- | 1 ft || 1 mi || ft |- | 1 mi || ... || mi |- |}
Server load should be negligible, as the work involved is equivalent to template
transclusion (which far exceeds any math involved). It is technically possible
to implement unit conversion entirely using templates, the <span> tag, and CSS,
but such a solution would be horribly inelegant and currently infeasible due to
omission of the <span> tag.