pydicom.valuerep.DSdecimal

class pydicom.valuerep.DSdecimal(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 decimal.Decimal.

Parameters:
  • val (Union[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.

Notes

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

__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. E.g. if set '1.23e2', Decimal would write '123', but DS will use the original.

Methods

__init__(val[, auto_format, validation_mode])

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

adjusted()

Return the adjusted exponent of the number.

as_integer_ratio()

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

as_tuple()

Return a tuple representation of the number.

canonical()

Return the canonical encoding of the argument.

compare(other[, context])

Compare self to other.

compare_signal(other[, context])

Identical to compare, except that all NaNs signal.

compare_total(other[, context])

Compare two operands using their abstract representation rather than their numerical value.

compare_total_mag(other[, context])

Compare two operands using their abstract representation rather than their value as in compare_total(), but ignoring the sign of each operand.

conjugate()

Return self.

copy_abs()

Return the absolute value of the argument.

copy_negate()

Return the negation of the argument.

copy_sign(other[, context])

Return a copy of the first operand with the sign set to be the same as the sign of the second operand.

exp([context])

Return the value of the (natural) exponential function e**x at the given number.

fma(other, third[, context])

Fused multiply-add.

from_float()

Class method that converts a float to a decimal number, exactly.

is_canonical()

Return True if the argument is canonical and False otherwise.

is_finite()

Return True if the argument is a finite number, and False if the argument is infinite or a NaN.

is_infinite()

Return True if the argument is either positive or negative infinity and False otherwise.

is_nan()

Return True if the argument is a (quiet or signaling) NaN and False otherwise.

is_normal([context])

Return True if the argument is a normal finite non-zero number with an adjusted exponent greater than or equal to Emin.

is_qnan()

Return True if the argument is a quiet NaN, and False otherwise.

is_signed()

Return True if the argument has a negative sign and False otherwise.

is_snan()

Return True if the argument is a signaling NaN and False otherwise.

is_subnormal([context])

Return True if the argument is subnormal, and False otherwise.

is_zero()

Return True if the argument is a (positive or negative) zero and False otherwise.

ln([context])

Return the natural (base e) logarithm of the operand.

log10([context])

Return the base ten logarithm of the operand.

logb([context])

For a non-zero number, return the adjusted exponent of the operand as a Decimal instance.

logical_and(other[, context])

Return the digit-wise 'and' of the two (logical) operands.

logical_invert([context])

Return the digit-wise inversion of the (logical) operand.

logical_or(other[, context])

Return the digit-wise 'or' of the two (logical) operands.

logical_xor(other[, context])

Return the digit-wise 'exclusive or' of the two (logical) operands.

max(other[, context])

Maximum of self and other.

max_mag(other[, context])

Similar to the max() method, but the comparison is done using the absolute values of the operands.

min(other[, context])

Minimum of self and other.

min_mag(other[, context])

Similar to the min() method, but the comparison is done using the absolute values of the operands.

next_minus([context])

Return the largest number representable in the given context (or in the current default context if no context is given) that is smaller than the given operand.

next_plus([context])

Return the smallest number representable in the given context (or in the current default context if no context is given) that is larger than the given operand.

next_toward(other[, context])

If the two operands are unequal, return the number closest to the first operand in the direction of the second operand.

normalize([context])

Normalize the number by stripping the rightmost trailing zeros and converting any result equal to Decimal('0') to Decimal('0e0').

number_class([context])

Return a string describing the class of the operand.

quantize(exp[, rounding, context])

Return a value equal to the first operand after rounding and having the exponent of the second operand.

radix()

Return Decimal(10), the radix (base) in which the Decimal class does all its arithmetic.

remainder_near(other[, context])

Return the remainder from dividing self by other.

rotate(other[, context])

Return the result of rotating the digits of the first operand by an amount specified by the second operand.

same_quantum(other[, context])

Test whether self and other have the same exponent or whether both are NaN.

scaleb(other[, context])

Return the first operand with the exponent adjusted the second.

shift(other[, context])

Return the result of shifting the digits of the first operand by an amount specified by the second operand.

sqrt([context])

Return the square root of the argument to full precision.

to_eng_string([context])

Convert to an engineering-type string.

to_integral([rounding, context])

Identical to the to_integral_value() method.

to_integral_exact([rounding, context])

Round to the nearest integer, signaling Inexact or Rounded as appropriate if rounding occurs.

to_integral_value([rounding, context])

Round to the nearest integer without signaling Inexact or Rounded.

Attributes

imag

real

auto_format