Here's one way to do it:
complete = 999
total = 1000
pct = math.floor(complete * 100.0/total)/100
if complete / total >= 0.001:
pct = max(pct, 0.01)
print(f"Completed {complete} out of {total} ({pct:.0%})")
Output:
Completed 999 out of 1000 (99%)
if complete
is 1, it'll print 1% even though it's closer to 0.
A more complete solution
A more comprehensive solution that follows the same rational would round up for everything up to 50%, and then round down for everything from 50 to 100%:
def get_pct(complete, total):
pct = (complete * 100.0 / total)
if pct > 50:
pct = math.floor(pct) /100
else:
pct = math.ceil(pct) /100
return pct
complete = 1
total = 1000
print(f"Completed {complete} out of {total} ({get_pct(complete, total):.0%})")
#==> Completed 1 out of 1000 (1%)
complete = 999
total = 1000
print(f"Completed {complete} out of {total} ({get_pct(complete, total):.0%})")
#==> Completed 999 out of 1000 (99%)
complete = 555
total = 1000
print(f"Completed {complete} out of {total} ({get_pct(complete, total):.0%})")
#==> Completed 555 out of 1000 (55%)
complete = 333
total = 1000
print(f"Completed {complete} out of {total} ({get_pct(complete, total):.0%})")
#==> Completed 333 out of 1000 (34%)