Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7704719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:44:38+00:00 2026-05-31T23:44:38+00:00

I am developing a Python script that uses xlrd to obtain data from xls

  • 0

I am developing a Python script that uses xlrd to obtain data from xls files. I cannot figure out, however, how to print floating point numbers with the same precision as they have in the Excel file.

I tried using repr as suggested in https://stackoverflow.com/a/3481575/1296490 but this still gives different precision from the one I want.

For example, the Excel file has a cell with value -1.62717010683527 , then using
str(worksheet.cell(i,j).value) returns -1.62717010684,
while repr( worksheet.cell(i,j).value) returns -1.6271701068352695.
Using str(Decimal(worksheet.cell(i,j).value)) produces -1.6271701068352695095187044671547482721507549285888671875

None of the above gives me the original value from Excel. I have to process many such numbers each with different number of digits after the dot and it is not suitable to use %.10f etc.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:44:39+00:00Added an answer on May 31, 2026 at 11:44 pm

    Precision in Excel is confined to 15 significant figures.

    Use str( "%0.15g" % cell.value ) to achieve what you want:

    g - Same as "e" if exponent is greater than -4 or less than precision, "f" otherwise.
    (http://docs.python.org/release/2.4.4/lib/typesseq-strings.html)

    Do not forget 0. in "%0.15".

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a Python applicaton for server that uses Django + WSGI +
I am developing on cherrypy, I start it from a python script. For better
I am developing a Java application that calls a python script behind the scene.
I am developing a piece of software in Python that will be distributed to
I'm developing a python application and have a question regarding coding it so that
I have a python app, that I'm developing. There is a need to use
I'm developing an Python egg that has several .txt dependencies (they're templates used to
I am developing python in eclipse. As a result, python src files and test
I am developing a Python package for dealing with some scientific data. There are
I am developing a Python model that will support graphing if the correct modules

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.