a='{:.2%}'.format(42/50)
b='%.2f%%' % (2.322)
c=a[0:len(a)-1]
d=float(c)
print('a:%s'%a)
print('b:%s'%b)
print('c:%s'%c)
print('d+1:%s'%(d+1))
print(type(a))
print(type(b))
print(type(c))
print(type(d))
输出结果:
a:84.00%
b:2.32%
c:84.00
d+1:85.0
<class 'str'>
<class 'str'>
<class 'str'>
<class 'float'>
Python格式化输出百分比
最新推荐文章于 2022-05-29 16:43:15 发布