mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-12-13 19:31:15 +00:00
feat: round_value should support None
This commit is contained in:
@@ -23,7 +23,7 @@ def strip_trailing_zeros(value: str) -> str:
|
||||
return value.rstrip("0").rstrip(".")
|
||||
|
||||
|
||||
def round_value(value: float, decimals: int, keep_trailing_zeros=False) -> str:
|
||||
def round_value(value: float | None, decimals: int, keep_trailing_zeros=False) -> str:
|
||||
"""
|
||||
Round value to given decimals
|
||||
:param value: Value to be rounded
|
||||
@@ -31,7 +31,7 @@ def round_value(value: float, decimals: int, keep_trailing_zeros=False) -> str:
|
||||
:param keep_trailing_zeros: Keep trailing zeros "222.200" vs. "222.2"
|
||||
:return: Rounded value as string
|
||||
"""
|
||||
if isnan(value):
|
||||
if value is None or isnan(value):
|
||||
return "N/A"
|
||||
val = f"{value:.{decimals}f}"
|
||||
if not keep_trailing_zeros:
|
||||
|
||||
@@ -57,6 +57,8 @@ def test_round_value():
|
||||
assert round_value(222.2, 0, True) == "222"
|
||||
assert round_value(float("nan"), 0, True) == "N/A"
|
||||
assert round_value(float("nan"), 10, True) == "N/A"
|
||||
assert round_value(None, 10, True) == "N/A"
|
||||
assert round_value(None, 1, True) == "N/A"
|
||||
|
||||
|
||||
def test_format_duration():
|
||||
|
||||
Reference in New Issue
Block a user