﻿ What is a conversion expression?

What is a conversion expression?

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,  B is converted to units of A. 2. If an A=C and a C=B conversion exists,  convert B to C, then C to A 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,  convert B to A,  then do a normal add. 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,  convert B to A,  then do a normal subtract. A A A*A (Multiply) 1. An A*A conversion must exist. A B A*B (Multiply) B*A (Multiply) 1. If an A*B conversion exists,  use it 2. If an B*A conversion exists,  use it 3. If an A=B (Assign) is possible,  convert B to A,  then try A*A 4. If a B=A (Assign) is possible,  convert A to B,  then try B*B. A A A / A (Divide) 1. If an A/A conversion is defined, use it. 2. Do a normal divide  mark the result as unit-less. A B A / B (Divide) 1. If an A/B conversion is defined, use it. 2. If an A=B (Assign) is possible,  convert B to A,  then try A / A 3. If a B=A (Assign) is possible,  convert A to B,  then try B / B.

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.