(self, leading_space, type_sign)
return sign + valstr
Convert to string representation.
Convert to string representation.
Convert to string representation .
def to_str(self, leading_space, type_sign):
        """Convert to string representation."""
        if self.is_zero():
            return (b' ' * leading_space) + b'0' + (self.sigil * type_sign)
        # sign or leading space
        sign = b''
        if self.is_negative():
            sign = b'-'
        elif leading_space:
            sign = b' '
        mantissa, exp10 = self.to_decimal()
        digitstr = _get_digits(mantissa, self.digits, remove_trailing=True)
        # exponent for scientific notation
        exp10 += self.digits - 1
        if exp10 > self.digits - 1 or len(digitstr)-exp10 > self.digits + 1:
            # use scientific notation
            # this is self.to_str_scientific(
            #     n_before=1, n_decimals=self.digits-1, force_dot=False, group_digits=False)
            valstr = self._scientific_notation(digitstr, exp10, digits_to_dot=1, force_dot=False)
        else:
            # use decimal notation
            # usual: n_decimals = -exp10
            # this is self.to_str_fixed
            #     (self, n_decimals=-exp10, force_dot=False, group_digits=False) but with type_sign
            valstr = self._decimal_notation(digitstr, exp10, type_sign, force_dot=False)
        return sign + valstr
def to_str ( self , leading_space , type_sign ) : if self . is_zero ( ) : return ( b' ' * leading_space ) + b'0' + ( self . sigil * type_sign ) # sign or leading space sign = b'' if self . is_negative ( ) : sign = b'-' elif leading_space : sign = b' ' mantissa , exp10 = self . to_decimal ( ) digitstr = _get_digits ( mantissa , self . digits , remove_trailing = True ) # exponent for scientific notation exp10 += self . digits - 1 if exp10 > self . digits - 1 or len ( digitstr ) - exp10 > self . digits + 1 : # use scientific notation # this is self.to_str_scientific( #     n_before=1, n_decimals=self.digits-1, force_dot=False, group_digits=False) valstr = self . _scientific_notation ( digitstr , exp10 , digits_to_dot = 1 , force_dot = False ) else : # use decimal notation # usual: n_decimals = -exp10 # this is self.to_str_fixed #     (self, n_decimals=-exp10, force_dot=False, group_digits=False) but with type_sign valstr = self . _decimal_notation ( digitstr , exp10 , type_sign , force_dot = False ) return sign + valstr