fuzzyfields/numbers.py
def validate(self, value: Any) -> Union[float, int, decimal.Decimal, None]:
        """Convert a number or a string representation of a number to a
        validated number.

        :param value:
            string representing a number, possibly with thousands separator
            or in accounting negative format, e.g. (5,000.200) ==> -5000.2,
            or any number-like object
        :rtype:
            as returned by :meth:`Numeric.num_converter`
        :raises DomainError:
            Number out of allowed range
        :raises MalformedFieldError, FieldTypeError:
            Not a number
        """
        if isinstance(value, str):
            # Preprocess strings before passing them to self._num_converter
            # Remove thousands separator
            value = value.replace(',', '')

            # Convert accounting-style negative numbers, e.g. '(1000)'
            if value.startswith('(') and value.endswith(')'):
                value = '-' + value[1:-1]

            # Convert negative numbers formatted by Excel in some cases
            # '- 1000 -'
            elif value.startswith('- ') and value.endswith(' -'):
                value = '-' + value[2:-2]

        value = self._num_converter(value)
        if value is None:
            return None

        # Decimal has problems comparing to float/int
        valuef = float(value)

        if ((not self.allow_zero and valuef == 0)
                or (self.allow_min and valuef < self.min_value)
                or (not self.allow_min and valuef <= self.min_value)
                or (self.allow_max and valuef > self.max_value)
                or (not self.allow_max and valuef >= self.max_value)):
            raise DomainError(self.name, value, choices=self.domain_str)

        return value
Convert a number or a string representation of a number to a
        validated number.

        :param value:
            string representing a number, possibly with thousands separator
            or in accounting negative format, e.g. (5,000.200) ==> -5000.2,
            or any number-like object
        :rtype:
            as returned by :meth:`Numeric.num_converter`
        :raises DomainError:
            Number out of allowed range
        :raises MalformedFieldError, FieldTypeError:
            Not a number
        
Convert a number or a string representation of a number to a
validated number.

:param value:
string representing a number, possibly with thousands separator
or in accounting negative format, e.g.
Convert a number or a string representation of a number to a validated number . : param value : string representing a number possibly with thousands separator or in accounting negative format e . g .
def validate(self, value: Any) -> Union[float, int, decimal.Decimal, None]:
        if isinstance(value, str):
            value = value.replace(',', '')
            if value.startswith('(') and value.endswith(')'):
                value = '-' + value[1:-1]
            elif value.startswith('- ') and value.endswith(' -'):
                value = '-' + value[2:-2]
        value = self._num_converter(value)
        if value is None:
            return None
        valuef = float(value)
        if ((not self.allow_zero and valuef == 0)
                or (self.allow_min and valuef < self.min_value)
                or (not self.allow_min and valuef <= self.min_value)
                or (self.allow_max and valuef > self.max_value)
                or (not self.allow_max and valuef >= self.max_value)):
            raise DomainError(self.name, value, choices=self.domain_str)
        return value
def validate ( self , value : Any ) -> Union [ float , int , decimal . Decimal , None ] : if isinstance ( value , str ) : value = value . replace ( ',' , '' ) if value . startswith ( '(' ) and value . endswith ( ')' ) : value = '-' + value [ 1 : - 1 ] elif value . startswith ( '- ' ) and value . endswith ( ' -' ) : value = '-' + value [ 2 : - 2 ] value = self . _num_converter ( value ) if value is None : return None valuef = float ( value ) if ( ( not self . allow_zero and valuef == 0 ) or ( self . allow_min and valuef < self . min_value ) or ( not self . allow_min and valuef <= self . min_value ) or ( self . allow_max and valuef > self . max_value ) or ( not self . allow_max and valuef >= self . max_value ) ) : raise DomainError ( self . name , value , choices = self . domain_str ) return value
Convert a number or a string representation of a number to a
validated number.
Convert a number or a string representation of a number to a validated number .
"""Convert a number or a string representation of a number to a
        validated number.

        :param value:
            string representing a number, possibly with thousands separator
            or in accounting negative format, e.g. (5,000.200) ==> -5000.2,
            or any number-like object
        :rtype:
            as returned by :meth:`Numeric.num_converter`
        :raises DomainError:
            Number out of allowed range
        :raises MalformedFieldError, FieldTypeError:
            Not a number
        """ # Preprocess strings before passing them to self._num_converter # Remove thousands separator # Convert accounting-style negative numbers, e.g. '(1000)' # Convert negative numbers formatted by Excel in some cases # '- 1000 -' # Decimal has problems comparing to float/int
self
value
Any