Skip to main content

core.getpreservedvalueprecision

Home > @medplum/core > getPreservedValuePrecision

getPreservedValuePrecision() function​

A lab value's trailing zeros carry real significant-figure meaning (e.g. "1.30" vs "1.3"), but JSON numbers can't distinguish them - 1.30 and 1.3 parse to the identical float, and that distinction is gone the moment anything parses the response body as JSON. When the original precision was captured before that happened (in receive-from-health-gorilla, using a custom JSON.parse reviver to read the raw source of the parsed number), it's carried in the standard HL7 quantity-precision extension on valueQuantity's primitive sibling (_value), so the value can still be displayed with its original precision even though quantity.value itself is just the plain, precision-collapsed number.

Signature:

export declare function getPreservedValuePrecision(quantity: Quantity | undefined): number | undefined;

Parameters​

Parameter

Type

Description

quantity

Quantity | undefined

A FHIR Quantity, e.g. an Observation's valueQuantity.

Returns:

number | undefined

The number of digits after the decimal point to display, or undefined if no precision was preserved or the stored value is out of toFixed()'s valid range (quantity.value should then be displayed with its default precision).