Do not format as float if no precision specified
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Lukáš Kucharczyk 2023-10-13 16:58:12 +02:00
parent dba8414fd9
commit a6cd7a3430
1 changed files with 5 additions and 2 deletions

View File

@ -66,9 +66,12 @@ def format_duration(
match = re.search(rf"%(\d*\.?\d*){pattern}", formatted_string) match = re.search(rf"%(\d*\.?\d*){pattern}", formatted_string)
if match: if match:
format_spec = match.group(1) format_spec = match.group(1)
if format_spec: if "." in format_spec:
# Format the number according to the specifier # Format the number as float if precision is specified
replacement = f"{float(replacement):{format_spec}f}" 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 # Replace the format specifier with the formatted number
formatted_string = re.sub( formatted_string = re.sub(
rf"%\d*\.?\d*{pattern}", replacement, formatted_string rf"%\d*\.?\d*{pattern}", replacement, formatted_string