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

  • Home
  • SEARCH
  • 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 3221930
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:55:58+00:00 2026-05-17T15:55:58+00:00

Possible Duplicate: How to print number with commas as thousands separators? For example: >>

  • 0

Possible Duplicate:
How to print number with commas as thousands separators?

For example:

>> print numberFormat(1234)
>> 1,234

Or is there a built-in function in Python that does 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-17T15:55:59+00:00Added an answer on May 17, 2026 at 3:55 pm

    No one so far has mentioned the new ',' option which was added in version 2.7 to the Format Specification Mini-Language — see PEP 378: Format Specifier for Thousands Separator in the What’s New in Python 2.7 document. It’s easy to use because you don’t have to mess around with locale (but is limited for internationalization due to that, see the original PEP 378). It works with floats, ints, and decimals — and all the other formatting features provided for in the mini-language spec.

    Sample usage:

    print format(1234, ",d")    # -> 1,234
    print "{:,d}".format(1234)  # -> 1,234
    print(f'{1234:,d}')         # -> 1,234 (Python 3.6+)
    

    Note: While this new feature is definitely handy, it’s actually not all that much harder to use the locale module, as several others have suggested. The advantage is that then numeric output can be made to automatically follow the proper thousands (and other) separator conventions used in various countries when outputting things like numbers, dates, and times. It’s also very easy to put the default settings from your computer into effect without learning a bunch of language and country codes. All you need to do is:

    import locale
    locale.setlocale(locale.LC_ALL, '')  # empty string for platform's default settings
    

    After doing that you can just use the generic 'n' type code for outputting numbers (both integer and float). Where I am, commas are used as the thousand separator, so after setting the locale as shown above, this is what would happen:

    print format(1234, "n")    # -> 1,234
    print "{:n}".format(1234)  # -> 1,234
    

    Much of the rest of the world uses periods instead of commas for this purpose, so setting the default locale in many locations (or explicitly specifying the code for such a region in a setlocale() call) produces the following:

    print format(1234, "n")    # -> 1.234
    print "{:n}".format(1234)  # -> 1.234
    

    Output based on the 'd' or ',d' formatting type specifier is unaffected by the use (or non-use) of setlocale(). However the 'd' specifier is affected if you instead use the locale.format() or locale.format_string() functions.

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

Sidebar

Related Questions

Possible Duplicate: Reference: Comparing PHP's print and echo Is there any major and fundamental
Possible Duplicate: Is there a printf converter to print in binary format? Still learning
Possible Duplicate: Is there a printf converter to print in binary format? Consider this
Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} What's the
Possible Duplicate: C/C++ line number Hi, I have a simple error manager class that
Possible Duplicate: Python is operator behaves unexpectedly with integers I stumbled upon the following
Possible Duplicate: How to check if a number is a power of 2 I
Possible Duplicate: Weird Java Boxing Hi, Can somebody explain why the last print returns
Possible Duplicate: Unpythonic way of printing variables in Python? In PHP one can write:
Possible Duplicate: Print leading zeros with C++ output operator (printf equivalent)? #include <iostream> #include

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.