kerncraft/prefixedunit.py
def good_prefix(self, max_error=0.01, round_length=2, min_prefix='', max_prefix=None):
        """
        returns the largest prefix where the relative error is bellow *max_error* although rounded
        by *round_length*

        if *max_prefix* is found in PrefixedUnit.PREFIXES, returned value will not exceed this
        prefix.
        if *min_prefix* is given, returned value will atleast be of that prefix (no matter the
        error)
        """
        good_prefix = min_prefix
        base_value = self.base_value()

        for k, v in list(self.PREFIXES.items()):
            # Ignoring to large prefixes
            if max_prefix is not None and v > self.PREFIXES[max_prefix]:
                continue

            # Check that differences is < relative error *max_error*
            if abs(round(base_value/v, round_length)*v - base_value) > base_value*max_error:
                continue

            # Check that resulting number is >= 0.9
            if abs(round(base_value/v, round_length)) < 0.9:
                continue

            # Check if prefix is larger then already chosen
            if v < self.PREFIXES[good_prefix]:
                continue

            # seems to be okay
            good_prefix = k

        return good_prefix
def good_prefix(self, max_error=0.01, round_length=2, min_prefix='', max_prefix=None):
        """
        returns the largest prefix where the relative error is bellow *max_error* although rounded
        by *round_length*

        if *max_prefix* is found in PrefixedUnit.PREFIXES, returned value will not exceed this
        prefix.
        if *min_prefix* is given, returned value will atleast be of that prefix (no matter the
        error)
        """
        good_prefix = min_prefix
        base_value = self.base_value()

        for k, v in list(self.PREFIXES.items()):
            # Ignoring to large prefixes
            if max_prefix is not None and v > self.PREFIXES[max_prefix]:
                continue

            # Check that differences is < relative error *max_error*
            if abs(round(base_value/v, round_length)*v - base_value) > base_value*max_error:
                continue

            # Check that resulting number is >= 0.9
            if abs(round(base_value/v, round_length)) < 0.9:
                continue

            # Check if prefix is larger then already chosen
            if v < self.PREFIXES[good_prefix]:
                continue

            # seems to be okay
            good_prefix = k

        return good_prefix
returns the largest prefix where the relative error is bellow *max_error* although rounded
        by *round_length*

        if *max_prefix* is found in PrefixedUnit.PREFIXES, returned value will not exceed this
        prefix.
        if *min_prefix* is given, returned value will atleast be of that prefix (no matter the
        error)