python - Converting Decimal to % -
so have looked @ post here: how show percentage in python , used solution.
s = 'ftp' "{0:.0f}%".format(s.count('f') / 9 * 100)
the desired output 11%, when run code using format specified "0%" instead of 11% want. push in right direction appreciated.
if want show percentage, should use percent formatter directly:
>>> '{:.0%}'.format(s.count('f') / 9) '11%'
as others noted, python 2 use integer division if both arguments integers, can make constant float instead:
>>> '{:.0%}'.format(s.count('f') / 9.) '11%'
Comments
Post a Comment