Mahmoud Ayman
Mahmoud Ayman

Reputation: 197

I can't enter a big decimal number in Excel

I am using Python and I use this method to enter numbers in an Excel sheet:

file_loc = "C:/Users/mahmoud/Desktop/Book1.xlsx"
new_sheet = pyexcel.get_sheet(file_loc)
new_sheet.row += [2, 'Series2', 'Possible', 25.00000000000000004, 0]
new_sheet.save_as(file_loc)

My problem is that it doesn't enter 25.00000000000000004 in the Excel sheet but when I open it enters 25 instead. But when I decrease the number of decimal points a bit to 25.000004 it enters it normally as it is.

Is there a way I can enter 25.00000000000000004 in the Excel sheet as it is so that I can use it later?

Upvotes: 2

Views: 1062

Answers (2)

GuitarPicker
GuitarPicker

Reputation: 316

Unfortunately, Excel's 8-byte floating point numbers doesn't allow for more than 15 significant digits, and your example has 19.

If you don't need to perform math operations on them, then put quotes around it in Python and treat it like a text string instead. VBA can handle more decimal places with some of its 12-byte decimal types, so you may be able to convert the string to a number within VBA and return whatever result you need as a string again.

Upvotes: 2

Jeffery Williams
Jeffery Williams

Reputation: 216

Based on excel's specification, the number precision is limited to 15 digits. The number you listed has 18 digits of precision.
https://support.office.com/en-nz/article/Excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3

Upvotes: 4

Related Questions