- pydicom.valuerep.format_number_as_ds(val: float | Decimal) str ¶
Truncate a float’s representation to give a valid Decimal String (DS).
DICOM’s decimal string (DS) representation is limited to strings with 16 characters and a limited set of characters. This function represents a float that satisfies these constraints while retaining as much precision as possible. Some floats are represented using scientific notation to make more efficient use of the limited number of characters.
Note that this will incur a loss of precision if the number cannot be represented with 16 characters. Furthermore, non-finite floats (infs and nans) cannot be represented as decimal strings and will cause an error to be raised.