If you want to format floats with a comma within the f-string, you can either use replace after casting the float to a string:

position = 123.456
f"Position\t{str(position).replace('.',',')}"

A second option is to use the Python standard library module locale (but it is not thread-safe):

import locale
locale.setlocale(locale.LC_ALL, 'nl_NL')
f"Position\t{locale.format('%.3f', position)}"

A third option is to use the library babel (preferred in case of library routines):

from babel.numbers import format_decimal
f"Position\t{format_decimal(position, locale='nl_NL')}"

All three options return the same result for the given example:

'Position\t123,456'
Answer from kadee on Stack Overflow
🌐
Real Python
realpython.com › how-to-python-f-string-format-float
How to Format Floats Within F-Strings in Python – Real Python
April 24, 2024 - To use Python’s format specifiers in a replacement field, you separate them from the expression with a colon (:). As you can see, your float has been rounded to two decimal places. You achieved this by adding the format specifier .2f into the replacement field. The 2 is the precision, while the lowercase f is an example of a presentation type. You’ll see more of these later. Note: When you use a format specifier, you don’t actually change the underlying number. You only improve its display. Python’s f-strings also have their own mini-language that allows you to format your output in a variety of different ways.
Discussions

python - Fixed digits after decimal with f-strings - Stack Overflow
Is there an easy way with Python f-strings to fix the number of digits after the decimal point? (Specifically f-strings, not other string formatting options like .format or %) For example, let's s... More on stackoverflow.com
🌐 stackoverflow.com
python - How to print a number using commas as thousands separators - Stack Overflow
It uses the regular expressions feature: lookahead i.e. (?=\d) to make sure only groups of three digits that have a digit 'after' them get a comma. I say 'after' because the string is reverse at this point. ... For Python versions < 2.6 and just for your information, here are 2 manual solutions, they turn floats to ints but negative numbers work correctly: def format... More on stackoverflow.com
🌐 stackoverflow.com
f-string - converting float to string with set decimals and thousand separator
import locale a = 1100300.506 locale.setlocale(locale.LC_ALL, 'no_NO') locale._override_localeconv = {'thousands_sep': ' ','decimal_point': '.'} print(locale.format_string('%.2f', a, grouping=True)) More on reddit.com
🌐 r/learnpython
5
1
December 8, 2021
How to use python with comma (,) instead of dot (.) as decimal separator?

You convert it before printing.

>>> print(str(3.5).replace(".",","))
3,5

Above code converts 3.5 to string, then replaces dot with comma.

More on reddit.com
🌐 r/learnpython
5
2
July 3, 2018
🌐
Littlecolumns
littlecolumns.com › learn › python › f-strings
Formatting output with f strings - Python's Not (Just) For Unicorns
You know how we’ve been using print to print things out? And putting a comma between the sections? ... It’s definitely not the best way to do it - it’s old school, it’s inflexible, and just… people do it, it works, but it’s just not modern. As of Python 3.6, there is a cool fun new thing called f strings!
🌐
Built In
builtin.com › data-science › python-f-string
Guide to String Formatting in Python Using F-strings | Built In
| Video: Corey Schafer · More on Python: 10 Python Cheat Sheets Every Developer Should Know · Now, let’s round the number and add the % sign. ... We can also add a comma as a thousands separator.
🌐
W3Schools
w3schools.com › python › python_string_formatting.asp
Python String Formatting
To format values in an f-string, add placeholders {}, a placeholder can contain variables, operations, functions, and modifiers to format the value. ... A placeholder can also include a modifier to format the value.
🌐
mkaz.blog
mkaz.blog › working-with-python › string-formatting
Python String Formatting: Complete Guide
This comprehensive guide covers everything you need to know about Python string formatting, from basic f-strings to advanced formatting techniques.
🌐
Bobby Hadz
bobbyhadz.com › blog › python-format-number-thousands-separator-2-decimals
Format number with comma as thousands separator in Python | bobbyhadz
April 9, 2024 - 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) # ...
Find elsewhere
🌐
Cheatography
cheatography.com › brianallan › cheat-sheets › python-f-strings-number-formatting
Python F-Strings Number Formatting Cheat Sheet by BrianAllan - Download free from Cheatography - Cheatography.com: Cheat Sheets For Every Occasion
Contains formulas, tables, and examples showing patterns and options focused on number formatting for Python's Formatted String Literals -- i.e., F-Strings.
Rating: 0 ​ - ​ 2 votes
🌐
Real Python
realpython.com › videos › f-strings-format-round-floats
Using F-Strings to Format and Round Floats (Video) – Real Python
So to indicate to our f-string ... after a decimal point, you can put the colon, which separates the expression you want to evaluate in the curly brackets from the format specifier....
Published   November 12, 2024
🌐
Real Python
realpython.com › python-f-strings
Python's F-String for String Interpolation and Formatting – Real Python
November 30, 2024 - To write an f-string in Python, you need to add an f or F prefix before the string literal. Inside this string literal, you can include variables, objects, and expressions in curly braces. ... You can format numbers in f-strings by using format specifiers inside the curly braces. For example, you can use :.2f to format a floating-point number with two decimal places.
🌐
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
Comma (,) Both (may vary by location or other factors) Arabic decimal separator (٫) Data unavailable Map by NuclearVacuum on Wikipedia · 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 ·
🌐
ZetCode
zetcode.com › python › fstring
Python f-string - formatting strings in Python with f-string
May 11, 2025 - You can pad numbers with leading zeros to ensure fixed-width output, or use commas as thousands separators to make large numbers easier to read. These features are especially helpful for reports, tables, or any output where alignment and clarity matter. ... #!/usr/bin/python number = 42 big_number ...
🌐
CopyProgramming
copyprogramming.com › howto › how-to-format-a-float-with-a-comma-as-decimal-separator-in-an-f-string
Python: Formatting a Float Value in an f-string with Comma as Decimal Separator: A Guide
April 17, 2023 - To enable machine control in Python, I save the outcome to a text-file, which can be easily transferred to Excel. As Excel in the Netherlands uses a comma as the separator, I prefer to have the "position" outcome in the text-file as 123,456. To achieve this, I utilize the f-string method as follows: ... As a consequence, a dot decimal separator will be inevitable. Is there a way to replace all dots with commas in a file without having to iterate through the entire file and do it at the end?
Top answer
1 of 16
2569

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:

1234567 ⟶ 1_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.

🌐
Python Morsels
pythonmorsels.com › string-formatting
Python f-string tips & cheat sheets - Python Morsels
April 12, 2022 - Here's a summary of the various options within the format specification field for generic number formatting. These string formatting techniques work on all numbers (both int and float):
🌐
Bentley
cissandbox.bentley.edu › sandbox › wp-content › uploads › 2022-02-10-Documentation-on-f-strings-Updated.pdf pdf
A Guide to Formatting with f-strings in Python - CIS Sandbox
type as n or d and use spacing in the output. When variable = math.pi, the f-string · understands that variable is a floating-point number and displays it as such.
🌐
AskPython
askpython.com › home › how to print a number using commas as separators?
How to print a number using commas as separators? - AskPython
March 31, 2023 - The f-string is considered a ‘formatted string’ in python. The syntax of the f-string is very easy; it begins with the f letter and ends with the curly braces. The curly braces contain data that we want to replace the string.
🌐
Miguendes
miguendes.me › 73-examples-to-help-you-master-pythons-f-strings
Python F-String: 73 Examples to Help You Master It
November 7, 2020 - Learn Python f-strings by example. Use string interpolation to format float precision, multiline strings, decimal places, hex and other objects.
🌐
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
December 6, 2023 - To format thousand separators for ... and returns a string representation of the number with thousand separators. 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 ...