2 ms·
I haven't looked for this in the doc, but the f-string formatting is recursive: >>> import math >>> num_value = math.pi # to get long fractional part >>>
by rzzzwilson 5y ago
I haven't looked for this in the doc, but the f-string formatting is recursive:
>>> import math
>>> num_value = math.pi # to get long fractional part
>>> precision = 2
>>> print(f'{num_value:.{precision}f}')
3.14
>>> precision = 5
>>> print(f'{num_value:.{precision}f}')
3.14159