[英]PYTHON Format percentage as numeric
I have a question about converting a string output to a numeric output我有一个关于将字符串 output 转换为数字 output 的问题
For example:例如:
a = "{0:.2f}%".format(float(0.21*100))
a = '21.00%'
type(a)
str
I want the output in excel to show 21.00% in the cell which format is a numeric value no a string.我希望 excel 中的 output 在单元格中显示 21.00%,格式是数值而不是字符串。
Thank you~谢谢~
You have to remove the percent, or you can't change it to a numeric.您必须删除百分比,否则无法将其更改为数字。
float(a.replace("%", ""))
The better option is to just leave it at a = (0.21*100)
更好的选择是将它保留在a = (0.21*100)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.