This question already has answers here:
Formatting floats in Python without trailing zeros
                                
                                    (16个答案)
                                
                        
                                3年前关闭。
            
                    
我想使用Python从*.xls中使用模块xlrd提取电话号码,但显示如下:'16753435903.0'

这是代码:

opensheet = openxls.sheet_by_name(u'sms')
sheetrows = opensheet.nrows
for rownum in range(1, sheetrows):
    rowvalue = opensheet.row(rownum)
    execinfo = ""
    for colnum in range(1,5):
        execinfo += "'"+str(rowvalue[colnum].value)+"',"


关键部分:


  str(rowvalue [colnum] .value)


没有.0如何获取格式正确的电话号码?

最佳答案

这可能是一个非常简单的解决方法:将数字转换为int,然后再将其转换为字符串?

10-06 08:09