Python precision in string formatting with float numbers

后端 未结 2 548
遇见更好的自我
遇见更好的自我 2020-12-17 18:20

I don\'t understand why, by formatting a string containing a float value, the precision of this last one is not respected. Ie:

\'%f\' % 38.2551994324
         


        
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-17 18:49

    I would use the modern str.format() method:

    >>> '{}'.format(38.2551994324)
    '38.2551994324'
    

    The modulo method for string formatting is now deprecated as per PEP-3101

提交回复
热议问题