better percent formatting

This commit is contained in:
klemek
2021-01-11 17:38:55 +01:00
parent 155fe48e70
commit 8b6d5e5361
3 changed files with 22 additions and 13 deletions
+9
View File
@@ -96,6 +96,15 @@ def plural(count: int, word: str) -> str:
return f"{count:,} {word}{'s' if count != 1 else ''}"
def percent(p: float) -> str:
if p < 0.01:
return f"{100*p:.2f}%"
elif p < 0.1:
return f"{100*p:.1f}%"
else:
return f"{100*p:.0f}%"
# DATE FORMATTING