Help on class Percentage in module pydicts.percentage:
class Percentage(builtins.object)
| Percentage(numerator=None, denominator=None)
|
| A class to manage percentage values, providing arithmetic operations and formatting.
| It stores the percentage as a Decimal value (e.g., 0.5 for 50%).
|
| Methods defined here:
|
| __add__(self, p)
| Adds two Percentage objects.
| Returns None if either value is None.
|
| Args: p (Percentage): The other Percentage object to add.
|
| __eq__(self, b)
| Compares two Percentage objects for equality.
|
| Args: b (Percentage): The other Percentage object to compare with.
|
| __init__(self, numerator=None, denominator=None)
| Initializes a Percentage object.
|
| Args:
| numerator (int, float, Decimal, optional): The numerator of the fraction.
| denominator (int, float, Decimal, optional): The denominator of the fraction.
| If denominator is 0 or None, the value will be None.
|
| __lt__(self, other)
| Return self<value.
|
| __mul__(self, value)
| Multiplies this Percentage object by another Percentage object.
| Returns None if either value is None.
|
| Args: value (Percentage): The other Percentage object to multiply by.
|
| __neg__(self)
| Returns a new Percentage object with the negated value.
|
| __repr__(self)
| Returns the string representation of the percentage (e.g., "50.00 %").
|
| __sub__(self, p)
| Subtracts another Percentage object from this one.
| Returns None if either value is None.
|
| Args: p (Percentage): The other Percentage object to subtract.
|
| __truediv__(self, other)
| Divides this Percentage object by another Percentage object.
| Returns None if division by zero or other error occurs.
|
| Args: other (Percentage): The other Percentage object to divide by.
|
| float(self)
| Returns the percentage value as a float (e.g., 0.5 for 50%).
| Returns None if the internal value is None.
|
| float_100(self)
| Returns the percentage value multiplied by 100 as a float.
| Returns None if the internal value is None.
|
| isGETZero(self)
| Checks if the percentage value is greater than or equal to zero.
| Returns False if the value is not valid.
|
| isGTZero(self)
| Checks if the percentage value is strictly greater than zero.
| Returns False if the value is not valid.
|
| isLETZero(self)
| Checks if the percentage value is less than or equal to zero.
| Returns False if the value is not valid.
|
| isLTZero(self)
| Checks if the percentage value is strictly less than zero.
| Returns False if the value is not valid.
|
| isValid(self)
| Checks if the percentage has a valid (non-None) value.
|
| setValue(self, numerator, denominator)
| Sets the internal value of the percentage based on a numerator and denominator.
| If denominator is 0 or None, the value is set to None.
|
| Args:
| numerator (int, float, Decimal): The numerator.
| denominator (int, float, Decimal): The denominator.
|
| string(self, decimals=2)
| Returns the formatted string representation of the percentage (e.g., "50.00 %").
| Returns "None %" if the internal value is None.
|
| Args:
| decimals (int, optional): The number of decimal places to round to. Defaults to 2.
|
| value_100(self)
| Returns the percentage value multiplied by 100 (e.g., 50 for 0.5).
| Returns None if the internal value is None.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None