Use Python’s comma grouping format option: f'{number:,}' renders 1234567 as 1,234,567. For decimal values, combine the comma with a precision such as f'{number:,.2f}' to display two digits after the decimal point.
Use a comma separator for large numbers
For an integer, place a comma after the colon in an f-string format specification:
number = 1234567
print(f'{number:,}') # 1,234,567
The same format can be applied with Python’s built-in format() function:
number = 1234567
print(format(number, ',')) # 1,234,567
The comma option groups digits in threes for decimal integers and floating-point presentation. It is a fixed comma separator, not a setting that adapts to a user’s locale. See the Python format specification.
#1 Best Overall
Format floating-point values to a chosen precision
Add a presentation type and precision after the comma when you want a controlled number of digits after the decimal point. For example, .2f displays exactly two fractional digits:
number = 1234567.891
print(f'{number:,.2f}') # 1,234,567.89
Choose the precision that suits the display; the format specifier changes the rendered output, not the underlying numeric value.
Rank #2
Use locale-aware separators when output conventions vary
If digits should be grouped according to the active locale rather than always separated by commas, use the n presentation type:
number = 1234567
print(f'{number:n}')
The output depends on Python’s current locale settings, so it may not use commas. Python also notes that its default locale is not necessarily the system locale. Do not assume the machine’s regional setting is active in your program; configure or manage locale behavior explicitly when the output must follow a particular convention. Details are in the format specification’s locale behavior.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsFor more control through the standard library, locale.format_string() formats using the current LC_NUMERIC settings and can enable grouping. Its output also depends on the locale configured by the application; it is not inherently comma-formatted. See Python’s locale documentation.
Quick Recap
Best Value
Choose the formatting method
| Need | Use | What controls the separator |
|---|---|---|
| Always show commas in a conventional integer or decimal display | f'{number:,}' or format(number, ',') |
The format specification uses commas. |
| Show grouped digits with a fixed number of fractional digits | f'{number:,.2f}' (replace 2 with the desired precision) |
The format specification uses commas and the selected precision. |
| Follow configured locale conventions | f'{number:n}' or locale.format_string() |
The active locale settings determine grouping and formatting. |
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




