small fixes

This commit is contained in:
klemek
2021-01-11 19:34:22 +01:00
parent d48031e4b5
commit daad1a1563
6 changed files with 28 additions and 24 deletions
+4 -2
View File
@@ -108,8 +108,10 @@ def percent(p: float) -> str:
return f"{precise(100*p)}%"
def precise(p: float) -> str:
precision = abs(min(0, math.ceil(math.log10(p)) - 2))
def precise(p: float, *, precision: int = 2) -> str:
if p == 0:
return "0"
precision = abs(min(0, math.ceil(math.log10(p)) - precision))
s = "{:." + str(precision) + "f}"
return s.format(p)