Difference between revisions of "Writing and defining units"

Jump to: navigation, search

Note: You are currently viewing documentation for Moodle 3.3. Up-to-date documentation for the latest stable version of Moodle is probably available here: Writing and defining units.

(Unit field)
Line 204: Line 204:
[https://docs.moodle.org/33/en/Formulas_question_type < Formulas question type]
[https://docs.moodle.org/33/en/Formulas_question_type < Formulas question type]
[[Category:Formulas question type]]

Revision as of 00:25, 8 December 2017

< Formulas question type

Writing units

In the Formulas question, the writing of the unit symbols differs slightly from that in the SI because units are entered very simply on the computer. The rules for entering units in the Formulas question are described below.

  • The multiplication of unit symbols is indicated by a space, as prescribed in Section 5.1 of SI. The half-high (centred) dot (⋅) is not supported. For example, input 50 kN m (≡ 50 kN⋅m), as follows:
50 kN m
  • Division of unit symbols is indicated by a solidus (oblique stroke, /) or by negative exponents.For example, input 10 m/s, or 10 m s-1, as follows:
10 m/s
10 m s^(-1)
  • Exponentiation is indicated by the circumflex accent (^, UTF-8 #94; or ASCII code 94 (alt+94)).For example, input 4.7 m2, as follows:
4.7 m^2
  • Parentheses are required when there is a risk of misinterpretation. For example, do not input 8 kN m^-2 but rather:
8 kN m^(-2)
  • Permutations of the unit symbols are allowed. For example, the following two entries are considered identical:
3 m kg s^(-2)
3 kg m/s^2
Unit symbols are case sensitive. For example, kilonewton is written kN, not KN, kn or Kn.

Defining units

Units are defined on the Formulas question page, in the following three places:

  • For each part, in the Unit field.
  • For each part, in the Other rules field.
  • Under Extra options, in the [Global] - Basic conversion rule field.

Unit field

Specify a single or a combined unit.




You can also specify single and combined units separated by =.


In order to accept N and kg m/s2 as valid units, define Unit as follows:

N = kg m/s^2

Note that /s^2 must be placed at the end of the unit. Hence,  N = /s^2 kg m   and   N = kg /s^2 m   will lead to an error.

With the above setting, the following units will be considered correct:

kg m/s^2
kg m /s^2
m kg /s^2
m kg s^(-2)
s^(-2) kg m
s^(-2) m kg

In order to accept W, J/s and m2 kg s-3 as valid units, specify:

W = J/s = m^2 kg s^(-3)

Other rules field

Add prefixes that are not defined in the [Global] - Basic conversion rule by writing units followed by a list of prefixes.


Specify that meganewton (MN) is an acceptable unit by writing the following:

N: M;

Add conversions of single units by equating their values.

1 m = 39.3700787 in;

With the above conversion rule, the following answers are equivalent:

10 in
0.254 m
25.4 cm
254 mm

[Global] - Basic conversion rule field

Select a basic conversion rule. Prefixes and conversion factors for different basic rules are defined in the flle conversion_rules.php. In the file downloaded from the Moodle plugins directory, two rules are defined: None and Common SI units.


Select None if other rules contradicts the rule defined in [Global] - Basic conversion rule if any.

Common SI units

The Common SI units rule defines prefixes and conversion factors commonly used by physicists. The rule is as follows:

m: k d c m u n p f;
s: m u n p f;
g: k m u n p f;
mol: m u n p;
N: k m u n p f;
A: m u n p f;
J: k M G T P m u n p f;
eV: k M G T P m u;
W: k M G T P m u n p f;
Pa: k M G T P;
Hz: k M G T P E;
C: k m u n p f;
V: k M G m u n p f;
ohm: m k M G T P;
F: m u n p f;
T: k m u n p;
H: k m u n p;
//Conversion factors
J = 6.24150947e+18 eV;

Note that, for example, m: k c d m u n p f; is equivalent to:

1 m = 1e-3 km = 1e1 dm = 1e2 cm = 1e3 mm = 1e6 um = 1e9 nm = 1e12 pm = 1e15 fm;

As the Common SI units prefixes and conversion factors concern mainly physicists, the rule could be renamed Physics Units.


With the Common SI units rule, the following answers are equivalent:

5 s
5000 ms
5e9 ns
0.2 m/s
200 mm/s
1 m^2
10000 cm^2
1e-6 km^2

User defined rules

Other rules can be defined in the file conversion_rules.php.


Define a rule for structural engineering in the SI and US system of units:

$basic_unit_conversion_rules[101] = array('Structural Engineering','
// Prefixes
m: k c m ;
N: k M;
Hz: k;
s: m;
// Conversion factors
1 m = 3.28084 ft;
1 ft = 12 in;
3 ft = 1 yd;
1 kg = 0.001 t;
1 N = 0.22481 lb;
1 lb = 0.001 kip;


< Formulas question type