dropping trailing '.0' from floats

后端 未结 16 2166
傲寒
傲寒 2020-12-05 03:54

I\'m looking for a way to convert numbers to string format, dropping any redundant \'.0\'

The input data is a mix of floats and strings. Desired output:

0

16条回答
  •  遥遥无期
    2020-12-05 04:28

    Following code will convert contents of variable no as it is i.e. 45.60. If you use str the output will be 45.6

    no = 45.60
    
    strNo = "%.2f" %no
    

提交回复
热议问题