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

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -