# Buggy code
def format_satoshis(
    x, num_zeros=0, decimal_point=8, precision=None, is_diff=False, whitespaces=False
):
    if x is None:
        return "unknown"
    if precision is None:
        precision = decimal_point
    # format string
    decimal_format = ".0" + str(precision) if precision > 0 else ""
    if is_diff:
        decimal_format = "+" + decimal_format
    # initial result
    scale_factor = pow(10, decimal_point)
    if not isinstance(x, Decimal):
        x = Decimal(x).quantize(Decimal("1E-8"))
    result = ("{:" + decimal_format + "f}").format(x / scale_factor)
    if "." not in result:
        result += "."
    result = result.rstrip("0")
    # extra decimal places
    integer_part, fract_part = result.split(".")
    if len(fract_part) < num_zeros:
        fract_part += "0" * (num_zeros - len(fract_part))
    result = integer_part + DECIMAL_POINT + fract_part
    # leading/trailing whitespaces
    if whitespaces:
        result += " " * (decimal_point - len(fract_part))
        result = " " * (15 - len(result)) + result
    return result


# Traceback (ValueError)
Traceback (most recent call last):
File "electrum/electrum/gui/qt/__init__.py", line 242, in start_new_window
w = self.create_window_for_wallet(wallet)
File "electrum/electrum/gui/qt/__init__.py", line 191, in create_window_for_wallet
w = ElectrumWindow(self, wallet)
File "electrum/electrum/gui/qt/main_window.py", line 146, in __init__
self.send_tab = self.create_send_tab()
File "electrum/electrum/gui/qt/main_window.py", line 1153, in create_send_tab
self.fee_slider = FeeSlider(self, self.config, fee_cb)
File "electrum/electrum/gui/qt/fee_slider.py", line 19, in __init__
self.update()
File "electrum/electrum/gui/qt/fee_slider.py", line 49, in update
tooltip = self.get_tooltip(pos, fee_rate)
File "electrum/electrum/gui/qt/fee_slider.py", line 36, in get_tooltip
target, estimate = self.config.get_fee_text(pos, self.dyn, mempool, fee_rate)
File "electrum/electrum/simple_config.py", line 404, in get_fee_text
rate_str = format_fee_satoshis(fee_rate/1000) + ' sat/byte'
File "electrum/electrum/util.py", line 544, in format_fee_satoshis
return format_satoshis(fee, num_zeros, 0, precision=FEERATE_PRECISION)
File "electrum/electrum/util.py", line 524, in format_satoshis
result = ("{:" + decimal_format + "f}").format(x / scale_factor)
File "/usr/lib/python3.7/_pydecimal.py", line 3762, in __format__
spec = _parse_format_specifier(specifier, _localeconv=_localeconv)
File "/usr/lib/python3.7/_pydecimal.py", line 6192, in _parse_format_specifier
raise ValueError("Invalid format specifier: " + format_spec)

# Fixed code
def format_satoshis(
    x, num_zeros=0, decimal_point=8, precision=None, is_diff=False, whitespaces=False
):
    if x is None:
        return "unknown"
    if precision is None:
        precision = decimal_point
    # format string
    decimal_format = "." + str(precision) if precision > 0 else ""
    if is_diff:
        decimal_format = "+" + decimal_format
    # initial result
    scale_factor = pow(10, decimal_point)
    if not isinstance(x, Decimal):
        x = Decimal(x).quantize(Decimal("1E-8"))
    result = ("{:" + decimal_format + "f}").format(x / scale_factor)
    if "." not in result:
        result += "."
    result = result.rstrip("0")
    # extra decimal places
    integer_part, fract_part = result.split(".")
    if len(fract_part) < num_zeros:
        fract_part += "0" * (num_zeros - len(fract_part))
    result = integer_part + DECIMAL_POINT + fract_part
    # leading/trailing whitespaces
    if whitespaces:
        result += " " * (decimal_point - len(fract_part))
        result = " " * (15 - len(result)) + result
    return result