chore: Split strip_trailing_zeros function in formatters
This commit is contained in:
@@ -10,6 +10,15 @@ def decimals_per_coin(coin: str):
|
|||||||
return DECIMALS_PER_COIN.get(coin, DECIMAL_PER_COIN_FALLBACK)
|
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:
|
def round_value(value: float, decimals: int, keep_trailing_zeros=False) -> str:
|
||||||
"""
|
"""
|
||||||
Round value to given decimals
|
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}"
|
val = f"{value:.{decimals}f}"
|
||||||
if not keep_trailing_zeros:
|
if not keep_trailing_zeros:
|
||||||
val = val.rstrip('0').rstrip('.')
|
val = strip_trailing_zeros(val)
|
||||||
return val
|
return val
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user