Unit conversion

In all other cases, a change of the unit does not affect the numeric value.

The conversion logic described in the following may apply for the following contexts:

Conversion logic

In a simple scenario the configuration of the units to convert between refer to the same base unit. This is also formally given if one of the two units is the base unit..

...

Localized name

Alias

Base

Base value


Kilogram

kg

kg

1


Ton

t

kg

1000


Gram

g

kg

0.001

  • This configuration enables conversions between any two of the units involved (Gram, Kilogram and Ton)

However, it is not a requirement to refer to the same base unit for all units in the same dynamic enumeration:

...

Localized name

Alias

Base

Base value


Kilogram

kg

g

1000


Ton

t

kg

1000


Gram

g

g

1

  • This configuration also enables conversion between any two the units involved (Gram, Kilogram and Ton)

  • If necessary, multiple conversions are 'cascaded' to accomplish the task. This may involve units that are not 'Active entries' in the selection box.

  • As the default configuration for Time unit illustrates, this cascading approach creates transparency in enumerations for units covering a large numerical range.

Conversion and rounding

The final result of a potentially cascading conversion calculation will be rounded according to the settings for the value (see Numeric input with unit).

Example:

  • The value fied is restricted to 'Numbers only' and 'Number of Digits' is set to 1.

  • The current values read: 1750.0 'Kilogram'

  • After switching the unit from 'Kilogram' to 'Ton' the value reads: 1.8

  • After switching back from 'Ton' to 'Kilogram' the value reads: 1800.0

When the unit is changed, the rounded value is immediately stored as a change of the value.

Possible source of errors: 'Loops' in conversions

Cascading conversions introduce the risk of 'loops' or infinite cycles, as a result of inappropriate unit configurations.

...

Localized name

Alias

Base

Base value


Kilogram

kg

g

1000


Ton

t

kg

1000


Gram

g

kg

0.001

  • Here one of the conversion definitions is 'mirrored' by another, which results in an infinite loop over kg►g►kg►etc.

The following example contains a less obvious loop:


Localized name

Alias

Base

Base value


Kilogram

kg

g

1000


Ton

t

kg

1000


Gram

g

t

0.000001

  • Here the loop closes across all three units in the list: t►kg►g►t►etc.

Unit configuration loops must be carefully avoided, as infinite cycles in conversions may spontaneously freeze the HTML client when a unit selection changes.