pydicom.valuerep.DSfloat

class pydicom.valuerep.DSfloat(val: None | str | int | float | Decimal, auto_format: bool = False, validation_mode: int | None = None)[source]

Store value for an element with VR DS as float.

If constructed from an empty string, return the empty string, not an instance of this class.

Parameters:
  • val (str | int | float | Decimal) – Value to store as a DS.

  • auto_format (bool) – If True, automatically format the string representation of this number to ensure it satisfies the constraints in the DICOM standard. Note that this will lead to loss of precision for some numbers.

__init__(val: str | int | float | Decimal, auto_format: bool = False, validation_mode: int | None = None) None[source]

Store the original string if one given, for exact write-out of same value later.

Methods

__init__(val[, auto_format, validation_mode])

Store the original string if one given, for exact write-out of same value later.

as_integer_ratio()

Return integer ratio.

conjugate()

Return self, the complex conjugate of any float.

fromhex()

Create a floating-point number from a hexadecimal string.

hex()

Return a hexadecimal representation of a floating-point number.

is_integer()

Return True if the float is an integer.

Attributes

imag

the imaginary part of a complex number

real

the real part of a complex number

auto_format

as_integer_ratio()

Return integer ratio.

Return a pair of integers, whose ratio is exactly equal to the original float and with a positive denominator.

Raise OverflowError on infinities and a ValueError on NaNs.

>>> (10.0).as_integer_ratio()
(10, 1)
>>> (0.0).as_integer_ratio()
(0, 1)
>>> (-.25).as_integer_ratio()
(-1, 4)
conjugate()

Return self, the complex conjugate of any float.

fromhex()

Create a floating-point number from a hexadecimal string.

>>> float.fromhex('0x1.ffffp10')
2047.984375
>>> float.fromhex('-0x1p-1074')
-5e-324
hex()

Return a hexadecimal representation of a floating-point number.

>>> (-0.1).hex()
'-0x1.999999999999ap-4'
>>> 3.14159.hex()
'0x1.921f9f01b866ep+1'
imag

the imaginary part of a complex number

is_integer()

Return True if the float is an integer.

real

the real part of a complex number