Extensions.Quantities.Conversions

From emotive
Jump to navigation Jump to search

Classification

Name Conversions
Short Description Converts a Quantity or a Unit
Class Operations
Extension OTX Quantities extension
Group Overloading semantics
Exceptions -
Checker Rules -
Standard Compliant Yes

OTL Syntax

FloatValue = ToFloat(QuantityTerm);
StringValue = ToString(QuantityTerm);
StringValue = ToString(UnitTerm);

Description

  • When applied to a Quantity, the otx:ToFloat term will return the value of the Quantity normalized to the SI base units correlated to its display unit. For example a Quantity representing a speed value of 12.4 kilometers per hour will return a float value of 3.44 (as 12.4 km/h equal 3.44 m/s). Note that the display precision does not have any effect in this case.
  • When applied to a Quantity, the otx:ToString term will return a String containing the Quanitity's display value followed by a space (Unicode character U+0020) followed by the DISPLAY-NAME of the unit definition of its display unit. For computing the string representation of the display value, the same rules as specified for otx:ToString(Float) will apply. However, if the display precision property of the Quantity is set, the fixed-point-part will be rounded to the decimal place given by the display precision property. Negative precision values are also allowed (expressing decimal positions to the left of the point). For instance, a Quantity representing a speed value of 12.35 kilometers per hour with a display precision of 1 will be rendered as "12.4 km/h", whereas a Quantity of 1234.5 kilometers and a precision of -2 will be rendered as "1200 km", etc. For very large or very small values where otx:ToString yields a representation in scientific notation, the same rules will apply, so for instance a Quantity of 1.123*105 milliseconds with a display precision of 2 will be rendered as "1.12E5 ms". Furthermore, if the display precision is greater than the number of decimal digits representing the fractional part, the string will be stuffed by zero, e.g. a Quantity of 100.1 meters with a display precision of 3 yields "100.100 m".
  • When applied to a Unit, the otx:ToString term will return a String containing the DISPLAY-NAME of the corresponding unit definition. For example a Quantity representing a speed value of 12.4 kilometers per hour will be rendered as "12.4 km/h".
  • IMPORTANT: For all other OTX Core conversion terms, the behaviour when applied to Quantity or Unit values is unspecified. However, OTX applications may provide custom implementations of the conversion terms for Quantity or Unit arguments, if required.

Return Value

The Term returns the value, see table below.

Icons Note.png In OTX, Terms are categorized according to its return data type!
Data Type Description
Boolean The result of the comparision of the numerical quantities

Properties

Name Data Type Class Default Cardinality Description
QuantityTerm Quantity Term - [1] The Quantity which will be converted.
Name Data Type Class Default Cardinality Description
UnitTerm Unit Term - [1] The Unit which will be converted.

OTL Examples

/// Local Declarations

Float Float1 = 0.0;
String String1 = "";
String String2 = "";

/// Flow

// The assignment below should have the returned value 3.44 (from 3.44 m/s)
Float1 = ToFloat(12.4 [@Unit, "BL_DataLibraMIB.odx", "km/h"]);
// The assignment below should have the returned value "1200 km/h"
String1 = ToString(1234.5  [@Unit, "BL_DataLibraMIB.odx", "km/h", -2]);
// The assignment below should have the returned value "km"
String1 = ToString(1234.5  [@Unit, "BL_DataLibraMIB.odx", "km"]);

See also

Addition
Subtraction
Multiplication
Division
Modulo
Absolute Value
Negation
Relational Operations
Other Operations