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 6974647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:15:55+00:00 2026-05-27T17:15:55+00:00

I need to print or convert a float number to 15 decimal place string

  • 0

I need to print or convert a float number to 15 decimal place string even if the result has many trailing 0s eg:

1.6 becomes 1.6000000000000000

I tried round(6.2,15) but it returns 6.2000000000000002 adding a rounding error

I also saw various people online who put the float into a string and then added trailing 0’s manually but that seems bad…

What is the best way to do this?

  • 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-27T17:15:56+00:00Added an answer on May 27, 2026 at 5:15 pm

    For Python versions in 2.6+ and 3.x

    You can use the str.format method. Examples:

    >>> print('{0:.16f}'.format(1.6))
    1.6000000000000001
    
    >>> print('{0:.15f}'.format(1.6))
    1.600000000000000
    

    Note the 1 at the end of the first example is rounding error; it happens because exact representation of the decimal number 1.6 requires an infinite number binary digits. Since floating-point numbers have a finite number of bits, the number is rounded to a nearby, but not equal, value.

    For Python versions prior to 2.6 (at least back to 2.0)

    You can use the “modulo-formatting” syntax (this works for Python 2.6 and 2.7 too):

    >>> print '%.16f' % 1.6
    1.6000000000000001
    
    >>> print '%.15f' % 1.6
    1.600000000000000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our print team saves raster images as .eps files. We need to convert about
I need to print last 20 characters of string, but only whole words. Delimiter
Here is what I need to do. Get Date, convert to string and pass
I need a cross-platform library/algorithm that will convert between 32-bit and 16-bit floating point
I need to print out data into a pre-printed A6 form (1/4 the size
I need to print the date in the format of mm/dd/yyyy. if the date
I need to print records in a grid view, and need to preview it
i need to print out numbers 1-100 in a random order. the print statement
I need to print a receipt from my web based apps using dot matrix
I need to print the ASCII value of the given character in awk only.

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.