chore: Split strip_trailing_zeros function in formatters

This commit is contained in:
Matthias 2024-03-17 13:37:27 +01:00
parent d07ec50549
commit ca2d322eb8

View File

@ -10,6 +10,15 @@ def decimals_per_coin(coin: str):
return DECIMALS_PER_COIN.get(coin, DECIMAL_PER_COIN_FALLBACK)
def strip_trailing_zeros(value: str) -> str:
"""
Strip trailing zeros from a string
:param value: Value to be stripped
:return: Stripped value
"""
return value.rstrip('0').rstrip('.')
def round_value(value: float, decimals: int, keep_trailing_zeros=False) -> str:
"""
Round value to given decimals
@ -20,7 +29,7 @@ def round_value(value: float, decimals: int, keep_trailing_zeros=False) -> str:
"""
val = f"{value:.{decimals}f}"
if not keep_trailing_zeros:
val = val.rstrip('0').rstrip('.')
val = strip_trailing_zeros(val)
return val