def format(self, value):
        """
        Formats a value.

        @type value
          `float`
        """
        sign = (
            "" if self.__sign is None
            else "-" if value < 0
            else "+" if self.__sign == "+"
            else " ")

        if math.isnan(value):
            # Not a number.
            result = text.pad(self.__nan_str, self.__width, pad=" ", left=True)

        elif value < 0 and self.__sign is None:
            # Can't show negative number without sign.
            result = "#" * self.__width

        elif math.isinf(value):
            # Infinite value.
            result = text.pad(
                sign + self.__inf_str, self.__width, pad=" ", left=True)

        else:
            if value == 0:
                exp = 0
                mantissa = 0
            else:
                abs_value = abs(value)
                precision = 0 if self.__precision is None else self.__precision
                rnd_value = round(
                    abs_value,
                    int(math.ceil(precision - math.log10(abs_value))))
                exp = int(math.floor(math.log10(rnd_value)))
                mantissa = rnd_value / 10 ** exp
            int_value = int(mantissa)
            result = sign + str(int_value)
            if self.__precision is None:
                pass
            elif self.__precision == 0:
                result += self.__point
            else:
                frac = int(round((mantissa - int_value) * 10 ** self.__precision))
                frac = text.pad(str(frac), self.__precision, pad="0", left=True)
                result += self.__point + frac
            result += self.__exp
            result += "+" if exp >= 0 else "-"
            exp = text.pad(str(abs(exp)), self.__size, pad="0", left=True)
            if len(exp) > self.__size:
                # Doesn't fit.
                result = "#" * self.__width
            else:
                result += exp
        return result
dataset/ETHPy150Open twosigma/ngrid/ngrid/formatters.py/EFloatFormatter.format/original