Python处理Excel(五):读取Excel中的Int型数

来源:互联网 发布:paypal充值 淘宝 编辑:程序博客网 时间:2024/05/17 09:10

Excel把所有的数字都当作浮点型,xlrd只是单纯的从表格中读取数据,所以读到的数据也一定是浮点型。如果我们实际需要的是一个整数,那么可以使用int()函数处理读取的数据,如果表格中既有浮点数也有整数,

采用下面的程序可以解决这类问题:

if your_number==int(your_number): #checking for the integer:      int(your_number)      #solving your problem and printing the integerelse:      your_number          #printing the float if present

采用下面的程序也是可行的:

if your_number % 1 == 0:         int(your_number)else:         your_number


0 0
原创粉丝点击