Module:Val/units/doc: Difference between revisions
Content deleted Content added
Caleb Cooper (talk | contribs) |
Caleb Cooper (talk | contribs) |
||
| (4 intermediate revisions by the same user not shown) | |||
Line 132:
</pre>
This table falls into place unsorted, so when your unit accepts an [[Wikipedia:SI prefix|SI prefix]] you can test, say, k, m, and G, with your unit, and compare with e notations 1e3, 1e6, and 1e9 in the number. For example, Val sorts these two as equal: <code>1e3 m</code> (standard [[Wikipedia:scientific notation#E notation|e notation]]) and <code>1 km</code>.
;What to look for:
Line 158:
:{{#invoke:DemoTemplate|val|99|ul=m|upl=d}}
* The val user can compose a ''multiplier'' unit on the fly by using the {{para|end}} parameter to prepend to the unit, and ''these'' can also be individually linked. For example (in geology) there is already {{Val|333|ul=uBP}} to use with {{para|end}}:
:{{#invoke:DemoTemplate|val|333|end= [[Wikipedia:megaannum|Ma]]|ul=uBP}}".
For example [[Template:Val/list]] says
<code>m.s-1 '''{{big|[<nowiki/>[}}'''Metre per second|m&sdot;s<sup>&minus;1</sup>'''{{big|]<nowiki/>]}}'''</code> linking to an article titled ''[[Wikipedia:Metre per second|Metre per second]]'', not
<code>m.s-1 '''{{big|[<nowiki/>[}}'''Metre|m'''{{big|]<nowiki/>]}}'''&sdot;'''{{big|[<nowiki/>[}}'''Second|s'''{{big|]<nowiki/>]}}'''<sup>&minus;1</sup></code> which has separate links to already existing unit codes.
Line 175:
=== Sorting ===
{{details|topic=sorting |Wikipedia:Help:sorting }}
{{details|topic=scaling |Template:Ntsh}}
Val's sorting scale factor is for comparison to other Val units that might be sorted with it.
Where [[Wikipedia:Help:Sorting|Sorting]] is done on the wiki, it is done in [[Wikipedia:Help:table#Sortable tables|sortable tables]].
Val entries in a sortable table will need a fourth field sorting flag. It can be a number, an equation, or an <kbd>SI</kbd>, but it flags the same function: a wikitable sorting "scale".
Line 192:
For scaling a unit to sort properly, you need to pick a number for a sorting factor.
There are numerous examples at [[Template:Val/list]] and at [[Template:Val/sortkey/unit]]. A [[Wikipedia:system of units|system of units]] will have its base units, for example 1 bit; then the scale for sorting a kilobyte unit is then 8000 (eight bits per byte, times a kilo, or thousand). Or a year scale is seconds so that all ''times'' sort by seconds, which is a base unit. In general the scale shows to be "base unit" of the same type times the "SI prefix", and if it's not that simple, then the unit system's number has associated a number to it, such as Avogadro's number.
For example, the following defines a unit with code <kbd>billion</kbd>, symbol <kbd>billion</kbd>, link [[Wikipedia:1,000,000,000|1,000,000,000]], and scale <kbd>1e9</kbd> ({{val|1|e=9}}). After the following entry is saved to the database
<pre>
billion billion 1,000,000,000 1e9
Line 204:
SI is used because it scales Val expressions automatically, and it is a clean indicator that the unit will sort properly. It correctly scales any SI prefix for sorting, but not other unit codes.
For SI the unit symbol will not accept HTML, but will accept μ. HTML is not accepted at this time because in order to validate the entry, the unit code must differ from the unit symbol by exactly one valid [[Wikipedia:SI prefix|SI prefix]]. If there is no difference, or too much difference, it is an invalid definition for sorting purposes. The exception is for the Greek letter μ: if you used a character input application to "install" the Greek letter <code>μ</code> in your symbol, for your "easy to type" unit code, {{key|u}}, these two are not a character mismatch.
All unit entries that use SI will have the same base unit as the symbol at Val/units, but they will display properly at Val/list.
For example, kilo is a thousand, but you're defining km2 for kilometers squared, and need HTML. You can't use SI with HTML, so use 1000*1000, or 1000000 in the sorting field. Use [[Wikipedia:e notation|1e-6]] or 0.000001 or 1/100000 instead.
If the unit you are maintaining has SI prefixes and they are all likely to be sorted in a table, add up to twelve entries, one for each common SI unit. Some of these, like ''Meter'' in the example, may have their own article, but usually all go to the base unit's pagename. Here is how ''meter'' is defined.
<pre>
m [[Wikipedia:Metre|m]] SI
cm [[Wikipedia:Centimetre|m]] SI
dam [[Wikipedia:Decametre|m]] SI
dm [[Wikipedia:Decimetre|m]] SI
hm [[Wikipedia:Hectometre|m]] SI
km [[Wikipedia:Kilometre|m]] SI
Mm [[Wikipedia:Megametre|m]] SI
mm [[Wikipedia:Millimetre|m]] SI
um [[Wikipedia:Micrometre|µm]] 1/1000000
µm [[Wikipedia:Micrometre|m]] SI
nm [[Wikipedia:Nanometre|m]] SI
pm [[Wikipedia:Picometre|m]] SI
</pre>
| |||