Calculations

LabHQ supports calculated results within test methods, allowing results to be automatically calculated from test method inputs.

This guide provides an overview of how LabHQ processes calculations, including order of operations, rounding and decimal precision and handling of invalid calculations.


Order of Operations

LabHQ follows the standard BODMAS order of operations when evaluating calculations:

  1. Brackets
  2. Orders
  3. Division and Multiplication
  4. Addition and Subtraction

This means that calculations containing multiple mathematical operations are evaluated according to the standard mathematical order of precedence.

Brackets can be used within the calculation to control the order in which individual parts of the calculation are evaluated.

Example

For the calculation:

2 + 3 x 4

Multiplication is performed before addition, resulting in:

2 + 12 = 14

If brackets are used:

(2 + 3) x 4

The calculation within the brackets is performed first, resulting in:

5 x 4 = 20

Raw & Display Results

When LabHQ performs a calculation, it distinguishes between the raw result of the calculation and the display result presented to the user.

Raw Result

The raw result is the value produced by the calculation before any rounding or display calculations are applied.

The raw result:

  • Is retained by LabHQ.
  • Is not changed by rounding or other display formatting.
  • Is recorded in the audit trail.

This preserves the original calculated value regardless of how the result is presented.

Display Result

The display result determines how the calculated result is presented to users within LabHQ and on generated certificates.

The display result can be affected by:

  • Rounding - where the raw calculated result is rounded to a configured number of decimal places.
  • Display result calculations - which can be configured on a test method output to transform the raw result into a different value or string for presentation purposes.

Display result calculations can be used where the value that should be reported to the user differs from the underlying numerical result.

For example, a test method could be configured so that:

If result < 10, display "<10"

If the raw calculated result is 7.5 , LabHQ retains 7.5  as the underlying raw result but presents <10  as the display result within the application and on the certificate.

This allows reporting rules and conventions to be applied without replacing or altering the underlying calculated result.


Rounding & Decimal Precision

Where rounding is configured for a calculated output, LabHQ first performs the calculation and determines the raw result. Rounding is then applied to this value to produce the display result.

For example, if a calculation produces a raw result of:

3.3333333333

and the output is configured to display two decimal places, the display result will be:

3.33

The underlying raw result remains unchanged.

If no rounding is configured, the raw result is used for display, up to a maximum of 10 decimal places, unless a display result calculation has been configured to change how the result is presented.


Invalidation Calculations & Inputs

LabHQ validates calculations when they are evaluated. Where a calculation cannot be successfully completed, LabHQ will not present an incorrect numerical result.

Examples include:

  • Division by zero.
  • A required calculation input being missing.

Where an error prevents a calculation from being completed, the calculated output is displayed as:

??

This indicates that LabHQ has been unable to determine a valid result and that the calculation or its required inputs should be reviewed.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us