From a6cd7a34300838ec9da72e0d8928e940ddd9d441 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Fri, 13 Oct 2023 16:58:12 +0200 Subject: [PATCH] Do not format as float if no precision specified --- common/time.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/common/time.py b/common/time.py index 918ca5c..c37f67b 100644 --- a/common/time.py +++ b/common/time.py @@ -66,9 +66,12 @@ def format_duration( match = re.search(rf"%(\d*\.?\d*){pattern}", formatted_string) if match: format_spec = match.group(1) - if format_spec: - # Format the number according to the specifier + if "." in format_spec: + # Format the number as float if precision is specified replacement = f"{float(replacement):{format_spec}f}" + else: + # Format the number as integer if no precision is specified + replacement = f"{int(float(replacement)):>{format_spec}}" # Replace the format specifier with the formatted number formatted_string = re.sub( rf"%\d*\.?\d*{pattern}", replacement, formatted_string