ଛାଞ୍ଚ:Val
This ଛାଞ୍ଚ employs intricate features of template syntax.
You are encouraged to familiarise yourself with its setup and parser functions before editing the template. If your edit causes unexpected problems, please undo it quickly, as this template may appear on a large number of pages. You can conduct experiments, and should test all major changes, in either this template's sandbox, the general template sandbox, or your user space before changing anything here. |
This template is used to easily present values in scientific notation, including uncertainty and/or units, as prescribed by Wikipedia's Manual of Style. It wraps the entire result in a {{nowrap}} block, so that it never gets broken into separate pieces at the end of a line. (See WP:NBSP for more information on the usage of non-breaking spaces.)
Arguments
[ସମ୍ପାଦନା]There are four ways this template can be used:
{{val|number}}
- for displaying values without uncertainty/significance.{{val|number|uncertainty}}
- for displaying values with uncertainty like so ୧,୨୩୪±୫୬.{{val|number|upper uncertainty|lower uncertainty}}
- for displaying values with uncertainty like so ୧,୨୩୪+୫୬
−୭୮.{{val|number|(significance)}}
- for displaying values with significance like so ୧,୨୩୪(56).
They all take roughly the same arguments
1 | The value (must be a valid number) |
2 | The (upper limit of) uncertainty (must be a valid number) or significance (must be a valid number in parenthesis) |
3 | The lower limit of uncertainty (must be a valid negative number) |
e | The exponent for the power of 10 (optional). This will show up in the result as: ×10e .
|
u / ul | Activate units and any markup / with a link to a page about the unit (optional / optional) |
up / upl | Construct units, and this is the "per" unit that is the denominator / with a link to a page about the denominator (requires numerator from u or ul)
|
p | A prefix for the value (such as ∆, ⌀, etc.; optional). |
s | A suffix for the value (such as %, optional).
|
end | Appends something after the main value. For example, {{val|123.24|end=...}} gives ୧୨୩.୨୪... |
errend | Appends something after the uncertainty. For example, {{val|123.23|end=...|2.34|errend=...}} gives ୧୨୩.୨୩...±୨.୩୪... |
+errend & -errend | Appends something after the positive/negative uncertainties. For example, {{val|123.23|end=...|+2.34|+errend=...|-1.23|-errend=...}} gives ୧୨୩.୨୩...+୨.୩୪... −୧.୨୩... |
fmt | Allows alternative formatting using commas to the left of the decimal point as opposed gaps either side. For example, {{val|123123.123123|fmt=commas}} gives ୧,୨୩,୧୨୩.୧୨୩୧୨୩ |
nocategory | If set to any value, errors in the use of this template will not cause the page to be added to the Pages with incorrect formatting templates use category. This is useful for documentation and test pages that do not need to be fixed. |
See {{val/testcases}} for a list of examples of the correct output of {{val}} and the errors it may return when incorrectly used.
Errors
[ସମ୍ପାଦନା]There is strict checking on the validity of arguments; any incorrect use will result in an error, which is displayed using {{FormattingError}}. Pages that contain incorrect use of this template will show up on Category:Pages with incorrect formatting templates use.
Format of numbers
[ସମ୍ପାଦନା]{{Val}} produces formatting compliant with Wikipedia's Manual of Style.
The MOS recommends that numbers either be delimited using thin spaces either side of the decimal, or commas to the left and no delimiters to the right. Articles should be consistent wrt the style of delimiting. The template defaults to the former style, this can be adjusted using |fmt=
(see above).
Examples
[ସମ୍ପାଦନା]{{val|1234567890}}
→ ୧,୨୩,୪୫,୬୭,୮୯୦ {{val|1.23456789}}
→ ୧.୨୩୪୫୬୭୮୯ {{val|21563.252564425}}
→ ୨୧,୫୬୩.୨୫୨୫୬୪୪୨୫ [୧] Uncertainty/significance {{val|1.234|0.005}}
→ ୧.୨୩୪±୦.୦୦୫ {{val|1.234|+0.005|-0.006}}
→ ୧.୨୩୪+୦.୦୦୫
−୦.୦୦୬{{val|1.234|(5)}}
→ ୧.୨୩୪(5) Units {{val|1.234|u=m}}
→ ୧.୨୩୪ମି {{val|1.234|u=m2}}
→ ୧.୨୩୪ମି୨ {{val|1.234|ul=m}}
→ ୧.୨୩୪m {{val|123.4|ul=USgal}}
→ ୧୨୩.୪USgal {{val|12.34|ul=mpgimp}}
→ ୧୨.୩୪mpgimp {{val|12.34|u=deg}}
→ ୧୨.୩୪°deg {{val|1.234|0.005|u='}}
→ ୧.୨୩୪′±୦.୦୦୫′' {{val|1.234|+0.005|-0.006|u="}}
→ ୧.୨୩୪″+୦.୦୦୫″
−୦.୦୦୬″"Exponents {{val|1.234|e=5|ul=m}}
→ ୧.୨୩୪×୧୦୫m {{val|1.234|0.056|e=7}}
→ (୧.୨୩୪±୦.୦୫୬)×୧୦୭ {{val|1.23456|+0.00007|-0.00008|e=-9|ul=m/s}}
→ ୧.୨୩୪୫୬+୦.୦୦୦୦୭
−୦.୦୦୦୦୮×୧୦−୯m/s{{val|1.234|0.056|e=7|ul=psi}}
→ (୧.୨୩୪±୦.୦୫୬)×୧୦୭psi {{val|1.234|(5)|e=-2}}
→ ୧.୨୩୪(5)×୧୦−୨ Prefix/suffix {{val|p=Δ |12.34}}
→ Δ ୧୨.୩୪ {{val|p=+|12.34|u=%}}
→ +୧୨.୩୪%% {{val|12.34|0.25|s=%}}
→ ୧୨.୩୪±୦.୨୫% Numerator/Denominator {{val|1.234|e=7|ul=W|up=m2}}
→ ୧.୨୩୪×୧୦୭Wମି୨
- More examples
See the testcases at Val/testcases.
Performance impact
[ସମ୍ପାଦନା]For most uses, in the text of articles, Template:Val will not restrict performance, but when used inside the wikitext markup of large templates, there are some restrictions. When displaying integer amounts, Template:Val has an internal expansion depth of 15 levels, but for numbers with decimal portions, it uses 22 levels, or more.
How to add units
[ସମ୍ପାଦନା]The unit you will add is required to have a link version and a non-link version for stylistic reasons (including the ability of editors to avoid overlinking). The link version will be added to Val/unitswithlink to process the ul
and upl
parameters. The non-link version might need to be added to Val/units to process the u
and up
parameter; it depends on whether or not the unit needs markup, or if the characters users will give to the ul
or u
parameter are different than what is displayed, or if "technical reasons" are discovered. (See below.)
Note these points before adding units:
- For composite units you should probably link the whole, not individual units. For example the line you add would say
|m·s-1=[[Velocity|m·s{{sup|−1}}]]
linking to Velocity, not|m*s-1=[[Metre|m]]·[[Second|s]]{{sup|−1}}
. List of common physics notations has many examples of composite units that have their own page. - The val user can compose their own divisor unit from an existing unit, writing
{{val|ul=m|upl=s}}
to render their own "ms" with two links:m
to Meter ands
to Second. - The val user can compose their own multiplier units by using the
end
parameter to prepend a string. For example, to prepend "Ma", they could write{{val|333|end= Ma|ul=uBP}}
, rendering "୩୩୩ MauBP". These cannot be linked.
The technique involves activating "Show changes" to catch unintended changes that are otherwise difficult to detect in any of the many pages using val that would be affected.
- Edit {{Val/unitswithlink/test}}. The LHS of the "=" sign is what val users will give to the
ul
(orupl
) parameter. Activate "Show preview". This will run your test data through val, which would be similar to running val itself in a sandbox. Prove the intended link and markup here because you will not be able to show a preview in the next steps. Copy what you will be adding to the wiki with the next steps. Save the page to serve as a "current list". - Edit {{Val/unitswithlink}}. Paste the identical line proven in step 1. Sort order is not important. Show changes, and then save.
- If the unit will display differently from what is typed into
u=
, edit {{Val/units}}. Paste the identical line, and remove any links from the RHS of the "=" sign, being careful to leave any rendering work. Show changes, and then save. - Important. Run
{{Val|u=}}
and{{Val|ul=}}
in a sandbox and verify that your unit has an identical appearance in both cases. Edit {{Val/units}} to make any corrections. (The discrepancy occurred for technical reasons.)
The last step is an important to the manual of style for dates and numbers.
FAQ and comments
[ସମ୍ପାଦନା]- Q: Why should I use val?
- A1: {{Val}} formats numbers:
- inserts spaces between groups of digits, approximating SI standards
- properly formats uncertainties in measurements and significant digits, providing a ± character, etc.
- properly formats exponents of 10 and scientific notation
- replaces "-" (hyphen) with a "−" (minus sign)
- A2: It preserves spacing:
- It makes sure the value does not wrap at the end of a line, so that it can always be read as a single value on one line in the text.
- It spaces the various parts of the value where they should be
- A3: It automates the markup for, and a link to a displayed unit.
- A4: Val helps make Wikipedia more consistent. It adheres to the Wikipedia Manual of Style for numbers. Updates to the Wikipedia Manual of Style for numbers can be applied to this template, and result in automatic modification on values that use it. All this makes sure all values on all pages have the same look and feel because they will all use the same spacing, font size, positioning, etc, and makes updating and checking by the bots easier because they can recognize a value for what it is.
- Q: Why not use <math>?
- A: For the same reasons [[Help:Math#Pros_of_HTML|HTML might be preferred over ଛାଞ୍ଚ:TeX]]:
- Because the font in math tags differs both in face and size from the prose, which can disturb the layout of a page when used inline with the prose.
- You cannot cut and paste a bitmap image rendered by the Latex.
- Images are slower to load and use more bandwidth, which is especially bad for the mobile version of Wikipedia.
- <math> does not automatically adhere to the Wikipedia Manual of Style for numbers.
- Q: Are there any known issues with val?
- A1: Because numbers can only be stored with a limited precision by Wikipedia servers, val cannot handle very large numbers, such as 123456789123456789. This is reported using a {{FormattingError}}, so it should be easy to spot. Since there is very limited use for such large numbers, there is no fix planned for this.
- A2: This template has been in full use on many pages for quite some time without major problems or breaking changes. Technically, there is no good reason not to try val.
- Q: How should I use val?
- A1: Val probably already has your unit on its current list. If not, then your unit can be added.
- A2: To avoid over linking switch from the ul= to the u= parameter of the given unit.
See also
[ସମ୍ପାଦନା]- {{val}} subtemplates:
- {{val/delimitnum}}, for formatting a decimal number with delimiters between groups of digits.
- {{val/units}}, for formatting unit names (contents of parametersଛାଞ୍ଚ:Plaincodeorଛାଞ୍ଚ:Plaincode).
- {{val/unitswithlink}}, for formatting unit names with links (contents of parametersଛାଞ୍ଚ:Plaincodeorଛାଞ୍ଚ:Plaincode).
- {{formatting error}}, for reporting inconsistent parameters.
- {{valid}}, for checking number validity (parameters 1, 2, 3, e : value, and uncertainties, base-10 exponent).