Logo

Programming-Idioms

History of Idiom 65 > diff from v15 to v16

Edit summary for version 16 by :

Version 15

2015-10-29, 14:05:15

Version 16

2015-10-31, 14:40:53

Idiom #65 Format decimal number

From real value x in [0,1], create its percentage string representation s with one digit after decimal point. E.g. 0.15625 -> "15.6%"

Idiom #65 Format decimal number

From real value x in [0,1], create its percentage string representation s with one digit after decimal point. E.g. 0.15625 -> "15.6%"

Code
'{:.1%}'.format(x)
Comments bubble
``.1`` means only one digit after decimal point.
``%`` handels the "multiplication" and shows the percentage sign.
Doc URL
https://docs.python.org/3/library/string.html#formatstrings