Convert a string to integer with decimal in Python

后端 未结 7 1094
余生分开走
余生分开走 2020-11-29 03:33

I have a string in the format: \'nn.nnnnn\' in Python, and I\'d like to convert it to an integer.

Direct conversion fails:

>>> s = \'23.4567         


        
相关标签:
7条回答
  • 2020-11-29 04:05

    You could use:

    s = '23.245678'
    i = int(float(s))
    
    0 讨论(0)
提交回复
热议问题