Chapter 8. Units
Prev |  | Next

# Chapter 8. Units

Units give numbers meaning in the real world. They specify what is measured by the numbers and the scale used. Qalculate! fully incorporates units in calculations and includes all standard SI units as well as many non-standard local units. For a complete list of available units see Appendix C, Unit List or the unit manager.

## Currency

Among units, Qalculate! has support for currencies with up-to-date exchange rates. Currencies are normally referenced with the standard three letter code due to name clashes, but a number of currency unit can also be accessed through their regular name and symbol. U.S. dollars can, for example, be referenced both as USD and dollar/dollars, or with the $ symbol.

The exchange rates can to be updated manually from File → Update Exchange Rates, or automatically at specific intervals (by default once every week, but it can be changed in the preferences dialog), when needed (when currencies are converted).

## Conversion

Expressions can be converted to a specific unit directly in the expression entry with the “to” operator, which converts the left-hand expression (or the previous result) to a specified unit (e.g. “5 feet + 2 inches to cm” converts the result of “5 feet + 2 inches” to centimeters and displays it). Unit expressions may only contain units, prefixes, exponents, multiplication and division. By default, no prefix will be added to units typed without prefix, but this behavior can be modified by putting a question mark in front of the unit expression (“6 561 ft to m ≈ 2000 m” but “6 561 ft to ?m ≈ 2 km”). Type “to optimal” to get optimal unit, “to base” for base units, or “to mixed” to force the use of mixed units (see below). Other elements are ignored (except “bin”, “oct” and “hex”).

The unit conversion view can also be used. It is shown when pressing Conversion, Ctrl+C, Edit → Convert To Unit Expression... or Ctrl+T (the last two options moves to focus to the unit expression entry). Enter a unit expression in the text entry and press Enter (or click Convert), or select a unit from the list. An appropriate unit category will automatically be selected from units in the current result. If Continuous expression is checked subsequent results will automatically be converted, and if Add prefix the optimal prefix will be set for unit expressions without any prefix. A unit can be inserted directly into the expression entry from the list by middle click selection or using the context menu.

Figure 8.1. Unit Conversion View

The menu associated with the to keypad button also provides a automatically generated list of units for conversion.

The final way to convert to another unit is to use the predefined units in the Edit → Convert To Unit menu or press Convert Result in the unit manager, which also provides quick conversion of a value between two selected units. Edit → Set Prefix can be used to select a prefix.

It is also possible to let Qalculate! automagically convert the result to appropriate units with Edit → Convert To Optimal Unit or Edit → Convert To Base Units (or the corresponding options in the result context menu). If instead the corresponding choice is selected from Mode+Unit Display, each result will automatically be converted until the choice is deactivated (Mode+Unit Display → No Automatic Conversion).

By default (controlled by Mode → Unit Display → Convert To Mixed Units) certain units, such as time units and many imperial/U.S. customary units, are automatically converted to mixed units (e.g. “60.2 minutes = 1 hour to 12 seconds”). When explicitely converting to a specific unit the integer value of the selected unit is preserved (“1.51 h to min = 90 min + 36 s”) and mixed units is not used if otherwise the unit would not be present in the result (“6 in to ft = 0.5 ft”). This behavior can be modified by prepending the unit with a plus or minus sign (e.g. “174 cm to +in ≈ 5 ft + 8,5 in”, “1.51 h to -min = 90.6 min”).

## Unit creation/editing

There are three different unit classes in Qalculate! — base, alias and composite units. Base units are units defined as basis for other units. Meters and seconds are typical base units. Alias units is defined in relation to another unit. For example, hour is defined as an alias unit that equals 60 minutes which in turn is defined in relation to seconds. Finally, composite units are defined by a unit expression with multiple units. Composite units often have an alias unit associated with them, as they do not have a reference name on their own. For example, a joule is defined as an alias defined in relation to a composite unit defined as “Newton × meter”.

Select File → New → Unit, or click New in the unit manager, and the unit edit dialog pops up.

Figure 8.2. Unit Edit Dialog

First the unit class needs to be selected. Depending on the unit class, different elements in the dialog will be enabled. For all units, category and descriptive name can be specified to keep them well organized. A unit can also be hidden from unit menus with the corresponding check box, which can be useful for some composite units.

Base and alias units normally have three different name forms defined for use in expressions — abbreviation (e.g. “m”), singular (“meter”) and plural (“meters”). Composite units only have an internal name, used to reference the unit in definitions of other units.

For base units, the name is all that is needed. For alias units, on the other hand, a base unit, exponent and relation are necessary. The base unit must not necessarily be of the base unit class and it is recommended that an alias unit is defined in relation to the closest unit (e.g. 1ft = 3 hands, 1 hand = 4 in, and 1 in = 0.0254 m). The relation is usually just a number that tells how large quantity of the base unit is needed to get the alias unit (alias unit = base unit × relation). The check box below relation in the dialog specifies if the relation is exact or approximate. The exponent defines the exponential relation to the base unit, so that the alias unit equals the base unit raised to the exponent. For simple unit relations this gives: alias unit = relation × base unit^exponent.

It is possible to create units with non-linear relation to the base unit. Replace the factor with “\x” and the exponent with “\y” (e.g. “\x + 273.15” for degrees Celsius with Kelvin as base unit). For non-linear relations the reverse relation (for conversion back from the base unit) should also be specified (“\x - 273.15” for degrees Celsius).

Composite units need a unit expression with multiple units as base, in the base unit field. These expressions may only contain units, prefixes, exponents, multiplication and division (e.g. “km/h”).

Prev |  | Next
Chapter 7. Functions | Home | Chapter 9. Plotting