A conversion expression specifies how to convert a number from one unit to another. For example, to convert a length in metres to millimetres, you must multiply the metres length by 1,000. A conversion expression is what is used to do this.
Conversion expressions can be used in five different ways: to just convert a number from one unit to another, to add two numbers, to subtract two numbers, to multiply two numbers and to divide two numbers. Sometimes, the necessary arithmetic can be done without a conversion. For example, if you don't define a specific 'conversion' for adding two numbers, the system will just convert one to the units of the other and do a normal add. The full rules are shown in the table below. In this table A represents any unit of measure and B represents any unit of measure with different units to A. Where rules are given, one of them must be available. If not, the operation will be abandoned and the result will be undefined.
First units |
Second units |
Operation |
Rule |
A |
A |
A=A (Assign) |
No conversion required. |
A |
B |
A=B (Assign) |
1. If an A=B conversion exists, 2. If an A=C and a C=B conversion exists, |
A |
A |
A+A (Add) |
No conversion required. |
A |
B |
A+B (Add) |
1. If an A+B conversion is defined, use it. 2. If an A=B (Assign) is possible, |
A |
A |
A-A (Subtract) |
No conversion required. |
A |
B |
A-B (Subtract) |
1. If an A-B conversion is defined, use it. 2. If an A=B (Assign) is possible, |
A |
A |
A*A (Multiply) |
1. An A*A conversion must exist. |
A |
B |
A*B (Multiply) |
1. If an A*B conversion exists, 2. If an B*A conversion exists, 3. If an A=B (Assign) is possible, 4. If a B=A (Assign) is possible, |
A |
A |
A / A (Divide) |
1. If an A/A conversion is defined, use it. 2. Do a normal divide |
A |
B |
A / B (Divide) |
1. If an A/B conversion is defined, use it. 2. If an A=B (Assign) is possible, 3. If a B=A (Assign) is possible, |
By far the most common situation is a simple scaling factor to allow an assign operation. However, considerable flexibility is provided to cater for other situations too. For example, to convert from Fahrenheit to Celsius temperatures cannot be done with a simple scaling operation.
Any mathematically valid expression can be used, with any mathematical operation, including trigonometric functions. Within these expressions the units to be converted have special names. For the assign operation, the name Value is used to denote the units to be converted from. For all other operations, the name Value is used to denote the 'first units' in the table above, and the name OtherValue is used to denote the 'second units'.
For example, the expression
Value * OtherValue / 1,000,000
would convert two millimetre lengths to a square metres area.