-1

I have an excel coming from external source. I have a value in a cell which is 63.999 as shown below :

enter image description here

but in the top editing bar it is shown as 63999 as shown below :

enter image description here

I am using openpyxl to parse this Excel and it gives me 63999 as cell value.

wb = openpyxl.load_workbook(SigLexiconFilePath)
sheet = wb.active
print (sheet.cell(row = 1, column = 1).value)

How to get 63.999 using openpyxl?

Anudocs
  • 686
  • 1
  • 13
  • 54
  • The value is not a decimal value. It's an integer with value: `63999`. The point `.` is a thousands separator, not a decimal separator. So, either the value that you are parsing is not a decimal value or your parsing it the wrong way. Could you show your code? – funie200 Jun 06 '19 at 09:31
  • but i want to read it as it is inside the cell – Anudocs Jun 06 '19 at 09:33
  • Yes I know, but since the value that is in the excel sheet is `63999` and the value you are reading is `63999`, I don't know what you want. Do you want to convert it to the decimal value `63.999` or to a string with a thousands separator? – funie200 Jun 06 '19 at 09:35
  • I put the code in question. I want to read 63.999 which is shown in the cell. – Anudocs Jun 06 '19 at 09:36

1 Answers1

1

To print the value with a thousands separator you can use the following code from this answer:

"{:,}".format(value)

For your code that would be:

wb = openpyxl.load_workbook(SigLexiconFilePath)
sheet = wb.active
print ("{:,}".format(sheet.cell(row = 1, column = 1).value))

If you want to use a . instead of a ,, you can use the following code instead:

"{:,}".format(value).replace(',', ' ')
funie200
  • 3,688
  • 5
  • 21
  • 34
  • why it is shown as 63.999 inside the cell and 63999 inside the editing bar? – Anudocs Jun 06 '19 at 09:40
  • Like I said in comment on your question, `63999` is an integer and the `63.999` is just the same number with a thousands separator. You can check out [this](https://support.office.com/en-us/article/show-or-hide-the-thousands-separator-b9f8aee0-ef50-42e5-8fd7-6e3ab1493876) tutorial by Microsoft on how to disable the thousands separator if you would like to, so you can see that it is not a decimal number. – funie200 Jun 06 '19 at 09:41
  • but the real value is 63.999 . Here . represents decimel number. its not a thousand operator. – Anudocs Jun 06 '19 at 09:44
  • How do you know that it is a decimal number? Because if that is the case, the editing bar would not show you the number as an integer. – funie200 Jun 06 '19 at 09:45
  • Ok. I will check once again with the excel provider. – Anudocs Jun 06 '19 at 09:47