f-string with percent and fixed decimals?

Question:

I know that I can to the following. But is it possible to combine them to give me a percent with fixed decimal?

>>> print(f'{0.123:%}')
12.300000%
>>> print(f'{0.123:.2f}')
0.12

But what I want is this output:

12.30%
Asked By: tturbo

||

Answers:

You can specify the number of decimal places before %:

>>> f'{0.123:.2%}' 
'12.30%'
Answered By: Lord Elrond
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.