Use locale.format():

>>> import locale
>>> locale.setlocale(locale.LC_ALL, 'German')
'German_Germany.1252'
>>> print(locale.format('%.2f', 32757121.33, True))
32.757.121,33

You can restrict the locale changes to the display of numeric values (when using locale.format(), locale.str() etc.) and leave other locale settings unaffected:

>>> locale.setlocale(locale.LC_NUMERIC, 'English')
'English_United States.1252'
>>> print(locale.format('%.2f', 32757121.33, True))
32,757,121.33
>>> locale.setlocale(locale.LC_NUMERIC, 'German')
'German_Germany.1252'
>>> print(locale.format('%.2f', 32757121.33, True))
32.757.121,33
Answer from Tim Pietzcker on Stack Overflow
Top answer
1 of 16
2571

Locale-agnostic: use _ as the thousand separator

f'{value:_}'          # For Python ≥3.6

Note that this will NOT format in the user's current locale and will always use _ as the thousand separator, so for example:

12345671_234_567

English style: use , as the thousand separator

'{:,}'.format(value)  # For Python ≥2.7
f'{value:,}'          # For Python ≥3.6

Locale-aware

import locale
locale.setlocale(locale.LC_ALL, '')  # Use '' for auto, or force e.g. to 'en_US.UTF-8'

'{:n}'.format(value)  # For Python ≥2.7
f'{value:n}'          # For Python ≥3.6

Reference

Per Format Specification Mini-Language,

The ',' option signals the use of a comma for a thousands separator. For a locale aware separator, use the 'n' integer presentation type instead.

and:

The '_' option signals the use of an underscore for a thousands separator for floating point presentation types and for integer presentation type 'd'. For integer presentation types 'b', 'o', 'x', and 'X', underscores will be inserted every 4 digits.

2 of 16
408

I'm surprised that no one has mentioned that you can do this with f-strings in Python 3.6+ as easy as this:

>>> num = 10000000
>>> print(f"{num:,}")
10,000,000

... where the part after the colon is the format specifier. The comma is the separator character you want, so f"{num:_}" uses underscores instead of a comma. Only "," and "_" is possible to use with this method.

This is equivalent of using format(num, ",") for older versions of python 3.

This might look like magic when you see it the first time, but it's not. It's just part of the language, and something that's commonly needed enough to have a shortcut available. To read more about it, have a look at the group subcomponent.

Discussions

Add underscore as a thousandths separator for string formatting - Ideas - Discussions on Python.org
I can think of two different ways to do this: Special case the _ grouping_option to add an underscore in the thousandths places Add a new format specifier (like float_grouping): format_spec ::= [[fill]align][sign… More on discuss.python.org
🌐 discuss.python.org
1
February 26, 2021
python - Thousand separator in format string with floats - Stack Overflow
I want to have thousand separators in floats. What I'm doing is: >>> import locale >>> locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') 'en_US.UTF-8' >>> print '{0:n}'.format(123456.0) 123,456 · When the integer part has 7 or more digits it does not work: ... Is there a format string that would ... More on stackoverflow.com
🌐 stackoverflow.com
Space as a thousands separator in the format specification mini-language - Ideas - Discussions on Python.org
Could I put in a word for spaces as a grouping option in the format specification mini-language? Right now, comma and underscore are available – why not space as well? One doesn’t always want to change the locale to get the international standard for representation of numbers. More on discuss.python.org
🌐 discuss.python.org
1
December 1, 2024
python format string thousand separator with spaces - Stack Overflow
For printing number with thousand separator, one can use the python format string : '{:,}'.format(1234567890) But how can I specify that I want a space for thousands separator? More on stackoverflow.com
🌐 stackoverflow.com
🌐
Reddit
reddit.com › r/learnpython › f-string - converting float to string with set decimals and thousand separator
r/learnpython on Reddit: f-string - converting float to string with set decimals and thousand separator
December 8, 2021 -

I'm struggling with f-strings. I want to take in a float and return string with thousand separator and two decimals, for ex. 1000.106 would return 1 000.11 as a string. I got it to work, but it looks ugly. Anyone know how to do this simpler?

code:

a = 1100300.506
b = f'{a:,.2f}'
c = b.replace(',', ' ')
print(a)
print(b)
print(c)

This will return:

1100300.506
1,100,300.51
1 100 300.51

So I will get my string like I want it, but I'm sure it's not the best way to do this.

Using this in Norway is the reason for the spaces as thousand separator.

🌐
Bobby Hadz
bobbyhadz.com › blog › python-format-number-thousands-separator-2-decimals
Format number with comma as thousands separator in Python | bobbyhadz
You can use an expression in the f-string to format the number with a comma as the thousands separator, rounded to 2 decimal places. ... Copied!my_float = 15467.3 # ✅ Format a float as currency result = f'${my_float:,.2f}' print(result) # ...
🌐
Sololearn
sololearn.com › en › Discuss › 3235225 › thousand-separator-for-float-nums
thousand separator for float nums? | Sololearn: Learn to code for FREE!
August 25, 2023 - #numbers with thousands separator print(format(10000,",d")) print(format(10000.50,",d")) for the second line i get a value error for float nums is there another way to get the output as 10,000.50 https://code.sololearn.com/clRdE90GjCEV/?ref=app ... Angela , This is a sample that shows the use of format strings with also explanation what the arguments are meaning.
🌐
Python
peps.python.org › pep-0378
PEP 378 – Format Specifier for Thousands Separator | peps.python.org
March 12, 2009 - The ‘,’ option indicates that ... as a thousands separator. As with locales which do not use a period as the decimal point, locales which use a different convention for digit separation will need to use the locale module to obtain appropriate formatting. The proposal works well with floats, ints, and ...
🌐
Finxter
blog.finxter.com › 5-best-ways-to-convert-a-python-string-to-float-with-thousand-separator
5 Best Ways to Convert a Python String to Float with Thousand Separator – Be on the Right Side of Change
February 19, 2024 - A straightforward approach to convert a string with thousand separators to a float is to eliminate the commas using the replace() method and then convert the resulting string to a float with the float() function. This method is simple and effective for properly formatted strings.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › print-number-commas-1000-separators-python
Print number with commas as 1000 separators in Python - GeeksforGeeks
May 14, 2025 - In this program, we need to print the output of a given integer in international place value format and put commas at the appropriate place, from the right. Let's see an example of how to print numbers with commas as thousands of separators in Python. ... F-strings provide a concise and convenient way to embed python expressions inside string literals for formatting.
🌐
Python.org
discuss.python.org › ideas
Add underscore as a thousandths separator for string formatting - Ideas - Discussions on Python.org
February 26, 2021 - I can think of two different ways to do this: Special case the _ grouping_option to add an underscore in the thousandths places Add a new format specifier (like float_grouping): format_spec ::= [[fill]align][sign][#][0][width][grouping_option][.precision[float_grouping]][type] fill ::= align ::= " " | "=" | "^" sign ::= "+" | "-" | " " width ::= digit+ grouping_option ::= "_" | "," float_grouping ::= "_" precision ...
🌐
AskPython
askpython.com › python › examples › formatting-floating-points-python
Formatting Floating Points Before Decimal Separator in Python - AskPython
May 21, 2026 - The , in the format spec adds thousand separators automatically. The + forces a sign to appear for positive numbers too. These two tricks alone solved my report problem in about thirty seconds.
🌐
Python.org
discuss.python.org › ideas
Space as a thousands separator in the format specification mini-language - Ideas - Discussions on Python.org
December 1, 2024 - Could I put in a word for spaces as a grouping option in the format specification mini-language? Right now, comma and underscore are available – why not space as well? One doesn’t always want to change the locale to get the international standard for representation of numbers.
🌐
Finxter
blog.finxter.com › how-to-print-an-integer-with-commas-as-thousands-separators-in-python
How to Print an Integer with Commas as Thousands Separators in Python? – Be on the Right Side of Change
Using the modern f-strings is, in my opinion, the most Pythonic solution to add commas as thousand-separators for all Python versions above 3.6: f'{1000000:,}'. The inner part within the curly brackets :, says to format the number and use commas as thousand separators.
🌐
Python
python.org › dev › peps › pep-0378
PEP 378 -- Format Specifier for Thousands Separator | Python.org
December 3, 2009 - The ',' option indicates that commas ... as a thousands separator. As with locales which do not use a period as the decimal point, locales which use a different convention for digit separation will need to use the locale module to obtain appropriate ...
🌐
Towards Data Science
towardsdatascience.com › home › latest › apply thousand separator (and other formatting) to pandas dataframe
Apply Thousand Separator (and Other Formatting) to Pandas Dataframe | Towards Data Science
January 28, 2025 - Let’s start with the ‘Median Sales Price’ column and see how we can format it by adding the thousand comma separators and a dollar sign in the front. Below is the code that does the trick: df.loc[:, "Median Sales Price_formatted"] ='$'+ df["Median Sales Price"].map('{:,.0f}'.format) Image by Author · We use the python string format syntax '{:,.0f}'.format to add the thousand comma separators to the numbers.
🌐
Finxter
blog.finxter.com › 5-best-ways-to-format-numbers-with-thousand-separators-in-python
5 Best Ways to Format Numbers with Thousand Separators in Python – Be on the Right Side of Change
March 6, 2024 - This method uses Python’s built-in format() function to insert commas as thousand separators. The function works by specifying a format string, which in this case is {:,}, where the colon acts as a separator specifier and the comma indicates the type of separator.
Top answer
1 of 10
141

Here is bad but simple solution if you don't want to mess with locale:

'{:,}'.format(1234567890.001).replace(',', ' ')
2 of 10
38

Answer of @user136036 is quite good, but unfortunately it does not take into account reality of Python bugs. Full answer could be following:

Variant A

If locale of your platform is working right, then just use locale:

import locale
locale.setlocale(locale.LC_ALL, '')
print("{:,d}".format(7123001))

Result is dependent on your locale and Python implementation working right.

But what if Python formatting according to locale is broken, e.g. Python 3.5 on Linux?

Variant B

If Python does not respect grouping=True parameter, you can use locale and a workaround (use monetary format):

locale.setlocale(locale.LC_ALL, '')
locale._override_localeconv = {'mon_thousands_sep': '.'}
print(locale.format('%.2f', 12345.678, grouping=True, monetary=True))

Above gives 12.345,68 on my platform. Setting monetary to False or omitting it - Python does not group thousands. Specifying locale._override_localeconv = {'thousands_sep': '.'} do nothing.

Variant C

If you don't have time to check what is working OK and what is broken with Python on your platform, you can just use regular string replace function (if you want to swap commas and dot to dots and comma):

print("{:,.2f}".format(7123001.345).replace(",", "X").replace(".", ",").replace("X", "."))

Replacing comma for space is trivial (point is assumed decimal separator):

print("{:,.2f}".format(7123001.345).replace(",", " ")

🌐
Saturn Cloud
saturncloud.io › blog › how-to-format-thousand-separator-for-integers-in-a-pandas-dataframe
How to Format Thousand Separator for Integers in a Pandas DataFrame | Saturn Cloud Blog
May 1, 2026 - def format_int_with_commas(x): """ Formats an integer with commas as thousand separators. """ return f"{x:,}" In this function, we use Python’s f-string formatting syntax to format the number with commas as thousand separators ({x:,}).
🌐
Herrmann
herrmann.tech › en › blog › 2021 › 02 › 05 › how-to-deal-with-international-data-formats-in-python.html
How to deal with international data formats in Python – herrmann.tech
That is, in countries that use the dot as decimal, the comma is the thousands separator and vice versa. ... What people often do when interpreting those numbers with Python is simply using the replace method of the str class. In [1]: number = '12,75' In [2]: parsed = float(number.replace(',', '.')) In [3]: parsed Out[3]: 12.75