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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:23:19+00:00 2026-05-27T11:23:19+00:00

I want to put a bunch of floating point numbers into a fixed-width table.

  • 0

I want to put a bunch of floating point numbers into a fixed-width table. That is, I want a maximum of 12 characters used. I want a minimum of 10 decimals used (if available); however, if 10 decimals makes it take up more than 12 characters, then round. My original thought was to try something like this

# I only want 12 characters used total

num1 = 0.04154721841
num2 = 10.04154721841

# not what I want
print "{:<12.11g}".format((num1))
# what I want
print "{:<12.10f}".format((num1))

# not what I want
print "{:<12.10f}".format((num2))
# what I want
print "{:<12.11g}".format((num2))

There has to be a way to achieve this without writing a function to check every number and give formatting based on the above conditions. What am I missing?

  • 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-27T11:23:20+00:00Added an answer on May 27, 2026 at 11:23 am

    I’m not sure this is what you are looking for, since it’s not accomplished entirely with the format string, however, you could just use string slicing to lop-off the trailing chars when things get too long:

    num1 = 0.04154721841
    num2 = 10.04154721841
    num3 = 1002.04154721841
    
    print "{0:<12.11g}".format(num1)[:12]
    print "{0:<12.11g}".format(num2)[:12]
    print "{0:<12.11g}".format(num3)[:12]
    

    outputs:

    0.0415472184
    10.041547218
    1002.0415472
    

    Beyond that, I’d say you should just write a function, though I’m not an expert on the str.format stuff, so I may be missing something.

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

Sidebar

Related Questions

I have a bunch of 'rowviews' that I want to put in a vertical
I have a bunch of html I want to put into a database field:
Say that I have a table with a bunch of records, which I want
I want to put a bunch of packed integers into a file, e.g.: for
I have a bunch of functions that I want to put in either a
I have a page layout for my MOSS '07 site that I want put
I want to put individual JComboBoxes into each cells of a JTable. ie. The
i want to put the id into the colorbox below this code nom works
I have a directory with a bunch of XML documents and want to put
I want to put a flash banner(slider) to show a bunch of products iteratively.

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.