I am trying to format some numbers in Python as follows:
(number) -> (formatted number)
1 -> 01
10 -> 10
1.1 -> 01.1
10.1 -> 10.1
1.1234 -> 01.1
What formatting specification can I use for this?
What I tried: {:04.1f}does not work correctly if there is no decimal part, but {:0>2}works only for integers, {:0.2g}approaches, but does not add a leading zero and {:0>4.2g}adds too many zeros if there is no decimal part.
source
share