Previous Document Next Document

What query methods are supported for units of measurement?

You can perform queries involving units of measurement, such as value conversions. Linear-dimension unit objects (such as mm, in, m, cm, and pt) are supported, as are unit objects for angles (such as degrees or radians) and file size (such as KB, MB, or GB).

To provide a constant unit of measurement, you must include it in braces ( {} ) along with the unit value and unit of measurement.

  • {1 in} = 1 inch
  • {1 mm} = 1 millimeter

Certain math operations can be performed on units of measurement, as in the following examples:

  • {1 cm} + {1 mm} yields {1.1 cm}
  • {1 pt} * 3 yields {3 pt}

The following query methods are supported for units of measurement:

Method
Description
Example
Result
unit.Category()
Returns a string describing the unit category
{1 in硙.category
'Linear Dimensions'
unit.Power()
Returns the power of the unit
{1 in硙.power
3
unit.Unit()
Returns the unit name as a string
{1 in硙.unit
'in'
unit.DisplayUnit()
Returns the unit name and possible unit power (such as 'mm' or 'cm?#39;)
{1 in硙.displayUnit
'in?#39;
unit.Value()
Returns the value of the unit, in the current units of measurement
{1 in硙.value
1
unit.BaseValue()
Returns the base value of the unit, in base units. Base units are chosen for the category, and all the other units are internally represented in terms of these base units.
{1 in}.baseValue
254000
unit.Convert(string)
Converts the unit value to another unit of measurement of the same category
{1 in硙.convert('mm')
16387.064 mm?/b>

How are exponents handled?

In addition to the multiplication and division of units of measurement, exponents are supported in queries. Units of different degrees can be specified by using the following general syntax:

{value unit^power} 

Consider the following examples:

  • {2 mm^2} yields 2 sq. mm
  • {3 in^3} yields 3 cubic inches

Units of power zero (such as {2 mm^0}) evaluate to regular numeric values — that is, {2 mm^0} equals to a numeric value of 2.

Powers of 2 and 3 can be specified by using special characters ?/code> (U+00B2) and ?/code> (U+00B3) after the unit of measurement, as in the following examples:

  • {2 mm瞹 yields 2 sq. mm
  • {3 in硙 yields 3 cubic inches

Multiplying units increases the power of the unit, while dividing them decreases the power:

  • {2 mm} * {2 mm} yields {4 mm瞹
  • {4 mm瞹 / {1 mm} yields {4 mm}

Comparing units can be done only with units of the same power:

  • {2 mm} * {2 mm} = {4 mm瞹 yields True (because the comparison is correct)
  • {2 mm} * {2 mm} = {4 mm} yields an error (because mm?/code> is being compared to mm)

However, different units of the same unit category can be used in expressions:

  • {1 in} = {72 pt} yields True (because inches and points belong to the same unit category)

To eliminate rounding error, comparisons of units of measurement are performed with reduced precision. The default precision level is three decimal places of the largest unit involved in comparison. For precise comparison, the precise-equality operator ( == ) can be used. Consider the following expressions, given that 1 mm equals 2.83464566929134 pt:

  • {1 mm} = {2.835 pt} yields True
  • {1 mm} == {2.835 pt} yields False

When converting units, the unit power must be considered. To convert values between different units, the unit.convert method must be used. Consider the following examples:

  • {1 in}.convert('mm') yields {25.4 mm}
  • {1 in瞹.convert('mm') yields {645.16 mm瞹

Previous Document Next Document Back to Top

Copyright 2007 Corel Corporation. All rights reserved.