Jump to content

Help:Calculation: Difference between revisions

From Meta, a Wikimedia project coordination wiki
Content deleted Content added
If a number uses point delimiters every three digits (as in continental Europe) and the number is an integer below one million, removing the point can be done by multiplying by 1000.
Line 118: Line 118:
This applies even though e.g. <nowiki>{{NUMBEROFARTICLES}}</nowiki> produces (in this project) {{NUMBEROFARTICLES}}, i.e., it uses comma delimiters every three digits, and in some localized versions of MediaWiki point delimiters.
This applies even though e.g. <nowiki>{{NUMBEROFARTICLES}}</nowiki> produces (in this project) {{NUMBEROFARTICLES}}, i.e., it uses comma delimiters every three digits, and in some localized versions of MediaWiki point delimiters.


If a number uses point delimiters every three digits (as in continental Europe) and the number is an integer below one million, removing the point can be done by multiplying by 1000.
If a number uses point delimiters every three digits (as in continental Europe) and the number is an integer below one million, removing the point can be done by multiplying by 1000 (#expr interprets the point as a decimal point).


==See also==
==See also==

Revision as of 08:42, 23 April 2006

With the WikiMedia extension ParserFunctions one can do computations.

The expr function computes mathematical expressions. The syntax is:

{{ #expr: expression }}

The spaces are not needed. Inside numbers no spaces are allowed.

The supported operators (roughly in order of precedence) are:

Operator Operation Example
none {{#expr: 123456789012345}} = 1.2345678901234E+14
{{#expr: 0.000001}} = 1.0E-6
* Multiplication {{#expr: 30 * 7}} = 210
/ or div Division {{#expr: 30 / 7}} = 4.2857142857143
{{#expr: 30 div 7}} = 4.2857142857143
+ Addition {{#expr: 30 + 7}} = 37
- Subtraction (or negation) {{#expr: 30 - 7}} = 23
mod Modulo, gives the remainder of a division {{#expr: 30 mod 7}} = 2
round Rounds off the number on the left to the specified number
of digits after the decimal place, given on the right
{{#expr: 30 / 7 round 7}} = 4.2857143
Rounds off the number on the left to the specified power
of 10, given on the right
{{#expr: 1234567 round -3}} = 1235000
= Equality {{#expr: 30 = 7}} = 0
<> or != Inequality {{#expr: 30 <> 7}} = 1
< Less than {{#expr: 30 < 7}} = 0
> Greater than {{#expr: 30 > 7}} = 1
<= Less than or equal to {{#expr: 30 <= 7}} = 0
>= Greater than or equal to {{#expr: 30 >= 7}} = 1
and Logical AND {{#expr: 30 and 7}} = 1
or Logical OR {{#expr: 30 or 7}} = 1
not Logical NOT {{#expr: not 7}} = 0
{{#expr: not 0}} = 1
( ) Grouping operators {{#expr: (30 + 7) * 7 }} = 259

The boolean operators consider 0 to be false and any other number to be true. As output, "true" produces 1.

Numbers

In the numbers in submitted expressions a decimal point is allowed, and a non-integer result has a decimal point in it. Scientific notation is produced for numbers less than 1E-4 and for numbers greater than or equal to 1E+12 (see Template talk:Pow), but not accepted as input.

Thus:

  • {{#expr: 1/10000 *2}} gives 0.0002
  • {{#expr: {{#expr: 1/10000}} *2}} gives 0.0002.
  • {{#expr: 1/100000 *2}} gives 2.0E-5

but

  • {{#expr: 2E-05 * 2}} gives 4.0E-5.
  • {{#expr: {{#expr: 1/100000}} *2}} gives 2.0E-5.

Commas

Commas are neither accepted in input nor produced in output:

  • {{#expr: 123,456}} gives Expression error: Unrecognized punctuation character ",".

This applies even though e.g. {{NUMBEROFARTICLES}} produces (in this project) 143,744, i.e., it uses comma delimiters every three digits, and in some localized versions of MediaWiki point delimiters.

If a number uses point delimiters every three digits (as in continental Europe) and the number is an integer below one million, removing the point can be done by multiplying by 1000 (#expr interprets the point as a decimal point).

See also