dropping trailing '.0' from floats

后端 未结 16 2220
傲寒
傲寒 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:32

    Us the 0 prcision and add a period if you want one. EG "%.0f."

    >>> print "%.0f."%1.0
    1.
    >>> 
    

提交回复
热议问题