python中浮点数尾部无效0去掉和无效的‘.’号

方法一:

=  12.12300   #结果要求为12.123            
=  12.00      #结果为12
=  200.12000  #结果为200.12
=  200.0      #结果为200
 
print  'a==>' ,[ str (a), int (a)][ int (a) = = a]
print  'b==>' ,[ str (b), int (b)][ int (b) = = b]
print  'c==>' ,[ str (c), int (c)][ int (c) = = c]
print  'd==>' ,[ str (d), int (d)][ int (d) = = d]


方法二:

for  in  [ 12.12300 12.00 200.12000 200.0 ]:
     print ( '{:g}' . format (i))

猜你喜欢

转载自blog.csdn.net/woddle/article/details/78497289