Sjabloon:Rnd/doc

Uit informatiestandaarden
< Sjabloon:Rnd
Versie door Ahenket (overleg | bijdragen) op 18 jul 2013 om 09:13 (Nieuwe pagina aangemaakt met '{{Documentation subpage}} <!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE. --> ==Usage== This template rounds parameter 1 by parameter 2 decima...')
(wijz) ← Oudere versie | Huidige versie (wijz) | Nieuwere versie → (wijz)
Naar navigatie springen Naar zoeken springen

Usage

This template rounds parameter 1 by parameter 2 decimal places (goes the other way for negative rounding) and includes trailing zeros.

{{rnd|54.376|2}}     gives {{#invoke:Math|precision_format| 54.376 | 2}}
{{rnd|54.376|-1}}   gives {{#invoke:Math|precision_format| 54.376 | -1}}
{{rnd|68.4273E12|-10}} gives {{#invoke:Math|precision_format| 68.4273E12 | -10}}

For example, rounding by 1 gives 1 decimal digit, rounding by 0 gives integers, or rounding by -2 gives the amount in hundreds. Scientific notation is displayed for numbers greater than or equal to 1×109, or less than 1×10−4.

Examples:

  • {{rnd|2.0004|3}} gives {{#invoke:Math|precision_format| 2.0004 | 3}}
    • whereas {{#expr:2.0004 round 3}} gives 2
  • {{rnd|0.000020004|7}} gives {{#invoke:Math|precision_format| 0.000020004 | 7}}
  • {{rnd|0|8}} gives {{#invoke:Math|precision_format| 0 | 8}}
  • {{rnd|154268|-3}} gives {{#invoke:Math|precision_format| 154268 | -3}}
  • {{rnd|154568|-3}} gives {{#invoke:Math|precision_format| 154568 | -3}}
  • {{rnd|1200004|-1}} → {{#invoke:Math|precision_format| 1200004 | -1}}
  • {{rnd|1300004|-1}} → {{#invoke:Math|precision_format| 1300004 | -1}}
  • {{rnd|4.1e6|9}} → {{#invoke:Math|precision_format| 4.1e6 | 9}}
  • {{rnd|4.1e6|10}} → {{#invoke:Math|precision_format| 4.1e6 | 10}}
  • {{rnd|1542689271|-7}} → {{#invoke:Math|precision_format| 1542689271 | -7}}
  • {{rnd|1542689271|2}} → {{#invoke:Math|precision_format| 1542689271 | 2}}
  • {{rnd|7e9|-9}} → {{#invoke:Math|precision_format| 7e9 | -9}}
  • {{rnd|-123|1}} → {{#invoke:Math|precision_format| -123 | 1}}
  • {{rnd|-1200007|-2}} → {{#invoke:Math|precision_format| -1200007 | -2}}
  • {{rnd|-1234567899|-7}} → {{#invoke:Math|precision_format| -1234567899 | -7}}

As with #expr, the total number of significant digits is not more than 14:

  • {{rnd|1234567890.123456789|10}} → {{#invoke:Math|precision_format| 1234567890.123456789 | 10}}
  • {{rnd|123456789.0123456789|10}} → {{#invoke:Math|precision_format| 123456789.0123456789 | 10}}
  • {{rnd|.0001234567890123456789|20}} → {{#invoke:Math|precision_format| .0001234567890123456789 | 20}}

Internal details

The markup-based version of Template:rnd uses three subtemplates:

  • {{rnd/-}} — for trailing zeros
  • {{rnd/e+}} — for scientific notation for numbers greater than or equal to 109 or less than or equal to −109
  • {{rnd/e−}} — for scientific notation for numbers greater than −10−4 and less than 10−4 but not equal to zero

The Lua-based version of {{rnd}} uses Module:Math and always has an expansion depth of 3. However, the markup-based version has an expansion depth of 9–15, which depends on the size of the numbers (integer results use depth 9, decimals use depth 12), where astronomical numbers can hit expansion depth of 15 levels, for {{rnd|56.44e33|-32}} → 5.64 × 1034.

TemplateData

<templatedata>{ "description": "Rounds (parameter 1) by (parameter 2) decimal places, and formats. Scientific notation is used for numbers greater than 1×10^9, or less than 1×10^−4.", "params": {

 "1": {
   "label": "number",
   "description": "The number to be rounded",
   "type": "number",
   "required": true
 },
 "2": {
   "label": "decimal places",
   "description": "The number of decimal places, if negative the number is rounded so the last (parameter 2) digits are zero",
   "type": "number",
   "required": true
 }

}}</templatedata>


See also