![]() | Bản mẫu này sử dụng những tính năng phức tạp của cú pháp bản mẫu.
Bạn được khuyến khích làm quen với cấu trúc của bản mẫu này và các hàm cú pháp trước khi sửa đổi bản mẫu. Nếu sửa đổi của bạn gây ra lỗi không mong muốn, hãy sửa chữa hoặc lùi lại nhanh chóng, vì bản mẫu này có thể xuất hiện trên một số lượng lớn trang. |
This template is used to easily present values in scientific notation, including uncertainty and/or units, as prescribed by Wikipedia's Manual of Style.
Chú ý: Các tham số đầu vào phải tuân theo quy tắc tiếng Việt: |1=1.234,5678
hoặc |1=1234,5678
, chứ không phải |1=1,234.5678
.
Val stands for the number value that is its first parameter. Val specializes in scientific notations and uncertainty notations, and in a measurement value with physical units. It formats the number (with possible unit) according to the Manual of Style and keeps the expression from wrapping across lines.
Express a numeral:
{{val|123456.78901}}
→ value, formated with gaps: 12345678901, or with |fmt=commas
→ 12345678901.{{val|number|number}}
→ value ± uncertainty, like 123478±56{{val|number|(number)}}
→ value(uncertainty), like 12345(56).{{val|number|number|number}}
→value +uncertaintyExpress a measurement value with a unit, for example {{val|4|ul=m/s2}}
→ 4 m/s2. The keyboard characters m/s2 are a "unit code" that |u=m/s2
marks up, or that |ul=m/s2
additionally links to its articulation.
Because the unit spacing and markup is a style issue, Val provides these for you. There are a large number of unit codes that Val understands and keeps "up to code". A unit code is usually composed of one or more abbreviated unit names and the usual math symbols on the typical keyboard. See {{Val/units}}.
Some unit-code flexibility is provided by having four parameters to work the unit-code system: whether to link one or not, (see Overlinking) , and whether to form a ratio or not with a unit code.
{{val|number|u=unit code}}
→ number markup , such as 98 m/s2{{val|number|ul=unit code}}
→ number [[Article|markup]], such as 98 m/s2{{val|number|u=unit code|upl=unit code}}
→ number markup/[[Article|markup]], such as 98 m/s2{{val|number|ul=unit code|up=unit code}}
→ [[Article|markup]]/markup, such as 98 m/s2To bypass the unit code system, if |u=
does not recognize your unit code, it will accept any wikitext and render it as usual.
{{val|5.4|u=[[kg]]⋅[[meter|m]]/s<sup>2</sup>}}
→ 54 kg⋅m/s2{{val|7.6|u=[[metre per second squared|m/s<sup>2</sup>]]}}
→ 76 m/s2See below for § How to add units to the unit code system.
Sometimes a number and unit code is not enough. A prefix or suffix are also available, |p=
and |s=
.
{{val|7600|u=C⋅Ga|p=>|s=<}}
→ >7600 C⋅Ga<{{val|7600|u=C|p=<span style="color:green"><sup>|s=</span></sup>}}
→ 7600 CSee {{val/testcases}} to learn the val parameters by a example. It's comprehensive, and there's over 100 examples.
1st | The numeric basis of the value. Defaults to 100.
|
2nd | Uncertainty in either format.
|
3rd | Asymmetric uncertainty.
|
|e=
|
Exponential.
|
|fmt=
|
Format strings of digits. Accepts |fmt=commas for the integer part, but commas ignores the fractional part. Defaults to gaps, except for four digits. Four digits accept |fmt=gaps .
|
|u= or |ul= |
The unit code. Val adds a space and the unit.
|
|up= or |upl= |
A unit code, but Instead of a space Val adds a slash and the unit, a "per" unit (the denominator), to form a ratio.
|
|p= |
Prefix. Non-spaced, but accepts markup.
|
|s= |
Suffix. Non-spaced, but accepts markup.
|
|end= |
Add something between the base number and what follows. This is how Val can do numeric ranges.
|
|errend= or |+errend= and |-errend= |
Appends something after an uncertainty.
|
|sortval= |
Alternative sorting factor to 1 |
|us= or |ups= |
Alternative unit code for sorting. |
|long scale= |
Usually a unit is the short ton and billion means 1×109. But there are long versions of these units and others. Use |long scale=on to assign your unit to the long scale instead. The unit code's link will change and it will sort differently in tables. "See Long and short scales".
|
|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. |
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.
{{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 with respect to the style of delimiting. The template defaults to the former style, this can be adjusted using |fmt=
(see above).
A hidden sort key is added to the output for sorting in sortable tables. The sort key is based on the main value (parameter |1=
) and, if used, the exponent for the power of 10 (parameter |e=
) and/or units (parameters |u=
, |ul=
, |up=
and/or |upl=
). Where necessary, units are converted to base SI units for the purpose of the sort key, which is produced by {{ntsh}}. Several units are covered; see § How to add units for those which are not. To omit the sort key use |sortable=off
.
{{val|1234567.1234567}}
→ 12345671234567
{{val|.1234567}}
→ 1234567
{{val|+1234567}}
→ +1234567
{{val|-1234567}}
→ −1234567
{{val|1.234|0.005}}
→ 1234±0005
{{val|1.234|+0.005|-0.006}}
→ 1234+0005
−0006
{{val|1.234|(5)}}
→ 1234(5)
{{val|1.234|u=m}}
→ 1234 m
{{val|1.234|u=m2}}
→ 1234 m2
{{val|1.234|ul=m}}
→ 1234 m
{{val|123.4|ul=USgal}}
→ 1234 gal Mỹ
{{val|12.34|ul=mpgimp}}
→ 1234 mpg‑Anh
{{val|12.34|u=deg}}
→ 1234°
{{val|1.234|0.005|u='}}
→ 1234′±0005′
{{val|1.234|+0.005|-0.006|u="}}
→ 1234″+0005″
−0006″
{{val|1.234|e=5|ul=m}}
→ 1234×105 m
{{val|1.234|0.056|e=7}}
→ (1234±0056)×107
{{val|1.23456|+0.00007|-0.00008|e=-9|ul=m/s}}
→ 123456+000007
−000008×10−9 m/s
{{val|1.234|0.056|e=7|ul=psi}}
→ (1234±0056)×107 psi
{{val|1.234|(5)|e=-2}}
→ 1234(5)×10−2
{{val|12.34|p=Δ }}
→ Δ 1234
{{val|12.34|u=%|p=≅}}
→ ≅1234%
{{val|12.34|0.25|s=%}}
→ 1234±025%
{{val|1.234|e=7|ul=W|up=m2}}
→ 1234×107 W/m2
See the testcases at {{val/testcases}}.
For very long list articles with hundreds of numeric entries, load times for that page will be much much faster by using html. No templates can compete with HTML on, for example List of nuclides.
Performance data is reported by MediaWiki software in the HTML page source of every page, and a very similar report is available on any preview page, below the edit box, titles "Parser profile data". For using Val inside other templates, note the performance parameter in these reports, called "Highest expansion depth". Numbers with fractional parts cost more Val-expansion depth than numbers with only integer parts.
For uses in any other page besides long list articles, Template:Val will have no noticeable impact on CPU time contributions to page-load times.
Add the unit to Bản mẫu:Val/units. Val defaults to looking up units at {{Convert}}, but units added here override that.
Note these points about composite units before adding units:
|m.s-1=[[Metre per second|m⋅s{{sup|−1}}]]
linking to Metre per second, not |m.s-1=[[Metre|m]]⋅[[Second|s]]{{sup|−1}}
.{{val|99|ul=m|upl=s}}
to render their own "99 m/s" with two links: m
to Meter and s
to Second.end
parameter to prepend a string. For example, in a geology article, to prepend "Ma", to the unit in 333 14C yr BP, use {{val|333|ul=uBP|end= [[megaannum|Ma]]}}
→ 333 Ma 14C yr BP". (The end
parameter accepts wikitext, so it can be linked.)After adding a unit, you can ensure that it sorts correctly in a table, especially if there are ten or twenty variations that differ only by an SI prefix. (See § Sorting above and Bản mẫu:Val/sortkey/unit.)
|ul=
to |u=
and from |upl=
to |up=
.u
in there names).