[英]python: percent format returning zeroes after the decimal place
我正在尝试将一些百分比打印到小数点后 4 位。 我的代码看起来像这样
for i in range(len(candidates)): #looping through the results
percentage_votes = "{:.4%}".format(results[i][1] / voters) #setting the number to a %
print(f'{results[i][0]}: {percentage_votes} ({results[i][1]})') #print result
打印时; 但是,它没有给我除法的小数位,而是返回 4 个小数位中的所有零。
Khan: 63.0000% (2218231)
Correy: 20.0000% (704200)
Li: 14.0000% (492940)
O'Tooley: 3.0000% (105630)
我需要在我的代码中更正什么才能给我进一步划分的数字? 谢谢!
我试过这个
"{:.4%}".format(3.4445453543)
输出: '344.4545%'
这让我想到可能是该部门没有报告浮动,
你能试试这个吗:
"{:.4%}".format(results[i][1] / float(voters))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.