CX_VALUE

Class hierarchy
Description:

This class allows to specify real numbers with a unit. Since each object of this class knows its own unit, only those arithmetic operations are possible, which also make sense: e.g. "1 m + 5 h" is an impermissible  addition, while "1 m + 30 cm" has the result "1,3 m". However, a value can also loose its unit: this state can be reached with operations such as "5 m / 3 cm". The result will be displayed as a value without a unit; e.g. "1,2356".

There are different units used in different countries, which can be held alltogether in the system. This brings up the question about a default unit. The USA for example, uses the unit "gallon" instead of "litre". The function ChangeDimension is available to maintain the required unit after an arithmetic operation.

Generating a new value, the unit gets reset to "pieces" by default.

Code example:

Var(value1, value2)
CreateTransObject(CX_VALUE) -> value1      // generate CX_VALUE
"50cm" value1 Put                          // and assign value
.................
55.4m -> value2                        // or 
................
value1 value2 +=     // Ergebnis :    value1 = 5590cm

Screen display

There are the following options to display objects of this class:

1. Applying an interface object of the type String. In this case, the object gets specified in a single input field. The flag NF_DIMENSIONED needs to be used, to make the unit also be shown in the export. Passing no flags, the two flags NF_DIMENSIONED and NF_AUTOMATIC_DECIMALS apply by default. The following figure shows an example(Program code):

2. Applying two interface objects of the type String - one for the specification of the number, and the other one for the unit. Here, the interface object Numeric can be used for the administration of the number. The fields  Enumeration or Combo can be used for the unit, so a variety of units is available for the user (Programmcode):

Remark: The elements of a complex unit are separated in ClassiX® with the multiplication sign "*" and with the according separator for fraction numbers (e.g. "/"). Here, it needs to be considered, that there are no brackets being used, to make the unit output less complicated. The unit "m/s*kg" for example equals "m/(s*kg)", not "m*kg/s". 

The object flags play an important role in connection with this display options and specific InstantView® statements, since they can be used to modify the display of object elements.

Operators
operator brief description
+, -, *, /    arithmetics
+=, -=, *=, /= arithmetics
>, <, =   comparisons

Method list (MDI)
function MA* parameter return brief description
abs OBJECT value without algebraic sign
arc OBJECT circular measure
arccos OBJECT Arcus-Kosinus
arcsin OBJECT Arcus-Sinus
arctan OBJECT Arcus-Tangens
AutoFormat INTEGER, INTEGER OBJECT returns a CX_VALUE object formatted according to the given number of pre-decimal places and decimal places
ceil OBJECT smallest integral number larger than object
ChangeUnitName (MLSTRING) rename unit
Convert (STRING) OBJECT convert into another unit
ConvertWeak (STRING) OBJECT like Convert, if mistake - return ZERO
CopyUnitName (INTEGER) change unit name
cos OBJECT cosine
cosh OBJECT hyperbolic cosine
cot OBJECT cotangent
DigitalHours input/output control of time units
EqualUnit (OBJECT) INTEGER checks, if two values have the same unit
exp OBJECT exponent
floor OBJECT largest integral number, smaller than object
Get1Value OBJECT return: number with value 1
GetUnitParameter OBJECT return: unit 
GetValue OBJECT return: object as value 
GetValuePer OBJECT return: object as value fraction
ValuePer (CX_VALUE) OBJECT return: object as value fraction
GrossAmount (OBJECT) OBJECT add percentage
HasUnit (STRING) INTEGER checks, if value has a specific unit
ImportObject (OBJECT) INTEGER setting number
IsArea INTEGER check unit division: suface areas
IsCompound INTEGER check unit division: complex units
IsCurrency INTEGER check unit division: currencies
IsDuration INTEGER check unit division: times 
IsEuroCurrency INTEGER check unit division: Euro currencies
IsGeometrical INTEGER check unit division: lengths, surface areas or volumetric unit 
IsLength INTEGER check unit division: lengths
IsPacking INTEGER check unit division: packaging
IsPieces INTEGER check unit division: Stückangaben 
IsTemperature INTEGER check unit division: temperatures
IsUserDefined INTEGER check unit division: self-defined units
IsVolume INTEGER check unit division: volumetric unit
IsWeight INTEGER check unit division: weights
ln OBJECT nat. logarithm 
log OBJECT logarithm. basis 10 (log10 x)
max (OBJECT) OBJECT  comparison "larger"   if (a > b) a else b
min (OBJECT) OBJECT  comparison "smaller"  if (a < b) a else b
NetAmount (OBJECT) OBJECT division with percentage
pow (OBJECT) OBJECT calculates number to the power of parameter number     xy
RateOfLastConversion OBJECT return: last conversion rate, that has been executed with UnitConvert or UnitCrossConvert by unit conversion tables
ResetUnitName cancel changes by ChangeUnitName and CopyUnitName
round (OBJECT) OBJECT like Round , but with object retur
RoundAutomatically OBJECT rounding number with precision resulting from the unit
RoundByPrecision rounding with current precision
SetDefaultCurrency setting default currency unit
SetDefaultUnit change pre-defined unit
SetValue STRING, INTEGER import String as a value
sin OBJECT sine
sinh OBJECT hyperbolic sine
sqrt OBJECT square root
tan OBJECT tangent
tanh OBJECT hyperbolic tangent
truncate (OBJECT) OBJECT like Truncate, but with object return
Unit * unit input/output control as a text
UnitEnum * unit input/output control as an internal value
UnitNumber INTEGER internernal value of the simple unit
ValuePer CX_VALUE CX_VALUE_PER generates a value fraction (CX_VALUE_PER)
Add   CX_AMOUNT CX_AMOUNT operator + as a function
AddAssign   CX_AMOUNT   operator += as a function
AdjustPrecision       adjusting precision
Amount     OBJECT return object value
AmountWeak   CX_AMOUNT    
ChangeSign       reverse algebraic sign
DiscreteRange   (OBJECT, OBJECT, OBJECT) INTEGER test number range
DivAssign   CX_AMOUNT   operator /= as a function
Divide   CX_AMOUNT CX_AMOUNT operator / as a function
GetFraction     OBJECT number as a fraction number
GetNumeric     OBJECT return: object as a real number
InWords   (INTEGER, INTEGER) MLSTRING convert number into numerals
IsNegative     INTEGER test negative algebraic sign
IsZero     INTEGER test if number is zero
MulAssign   CX_AMOUNT   operator *= as a function
Multiply   CX_AMOUNT CX_AMOUNT operator * as a function
PercentDifference   (OBJECT) OBJECT difference between two numbers as a percentage
Precision *     change precision
PrecisionAdjusted     OBJECT like AdjustPrecision, but with object return
Reciprocal     OBJECT create reciprocal value
Round   (INTEGER)   round number
Rounded   (INTEGER)    
SetNumeric   STRING, INTEGER   import String as a number
SetPrecision   (INTEGER)   set number of decimal places
SetZero       set number to zero
string   INTEGER CX_STRING provides string display of an object
SubAssign   CX_AMOUNT   operator -= as a function
Subtract   CX_AMOUNT CX_AMOUNT operator - as a function
Truncate   (INTEGER)   cutting off decimal places

Moreover, there are two common numbers of decimal places pre-defined. They can be called with the following (statistical) functions:

function name brief description
UnitPrecision   national unit precision
RateTablePrecision international unit precision

Data directory (DDI)
data field type reference class I* brief description
this CX_NUMERIC number
* I = indicateable data field

Application in AppsWH
module brief description
calcula.mod unit-calculator module
qm\tmprture_qm.mod conversion between temperature editing module