0

For a spreadsheet that has 40005613450016300, a 17 digit numeral, the type returned is float, for 4000561345001630, a 16 digit numeral, the type returned is int. Both cells in excel are formatted as "Number no decimal places". My python code is:

from openpyxl import load_workbook

def openSpreadsheet(fullFileName, workSheetName):
    workBook = load_workbook(fullFileName) # open the spreadsheet
    workSheet = workBook[workSheetName] # access the correct sheet
    return workSheet, workBook

workSheet, workBook = openSpreadsheet("Why Float.xlsx", "Sheet1")

for row in workSheet.values:
    print(row)
    print(type(row[0]))
sfyfer
  • 13
  • 3
  • Relevant [how-does-python-manage-int-and-long](https://stackoverflow.com/questions/2104884/how-does-python-manage-int-and-long) – stovfl Dec 13 '19 at 09:39
  • Precision is Excel files is limited. The file format is, therefore, unsuited for anything with high precision. – Charlie Clark Dec 14 '19 at 15:36
  • @Charlie Clark, thanks you lead me to this article which answers my question: https://www.microsoft.com/en-us/microsoft-365/blog/2008/04/10/understanding-floating-point-precision-aka-why-does-excel-give-me-seemingly-wrong-answers/ – sfyfer Dec 16 '19 at 08:18

0 Answers0