See the locale module.
This does currency (and date) formatting.
>>> import locale
>>> locale.setlocale( locale.LC_ALL, '' )
'English_United States.1252'
>>> locale.currency( 188518982.18 )
'$188518982.18'
>>> locale.currency( 188518982.18, grouping=True )
'$188,518,982.18'
Answer from S.Lott on Stack OverflowJerry Ng
jerrynsh.com โบ 3-useful-python-f-string-tricks-you-probably-dont-know
3 Useful Python F-string Tricks You Probably Donโt Know
August 3, 2021 - Format float type variable as a pretty-looking currency. Simple! Besides using it to format float type variables, we can even use f-string along with datetime type variable.
Videos
08:07
Python Tutorial #9: Formatting output with fstrings ๐ - YouTube
08:20
How to Use f-Strings (Formatted Strings) in Python - YouTube
19:43
Every F-String Trick In Python Explained - YouTube
11:16
Python F-Strings: Advanced Tips and Tricks - YouTube
F-Strings Have A Lot of Format Modifiers You Don't Know
05:14
Fstrings & Math - Python for Beginners - YouTube
Top answer 1 of 16
290
See the locale module.
This does currency (and date) formatting.
>>> import locale
>>> locale.setlocale( locale.LC_ALL, '' )
'English_United States.1252'
>>> locale.currency( 188518982.18 )
'$188518982.18'
>>> locale.currency( 188518982.18, grouping=True )
'$188,518,982.18'
2 of 16
115
New in 2.7
>>> '{:20,.2f}'.format(18446744073709551616.0)
'18,446,744,073,709,551,616.00'
http://docs.python.org/dev/whatsnew/2.7.html#pep-0378
W3Schools
w3schools.com โบ python โบ python_string_formatting.asp
Python String Formatting
Before Python 3.6 we had to use the format() method. F-string allows you to format selected parts of a string.
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 - Note: When you define a format using the form ".2e", you are using a similar, but not identical, formatting language to the language used by the more modern format specifiers. This time, you are using old-style printf-style string formatting. If you want to display currencies, you can use the locale.currency() function:
DNMTechs
dnmtechs.com โบ currency-formatting-in-python-3-simplified-guide
Currency Formatting in Python 3: Simplified Guide โ DNMTechs โ Sharing and Storing Technology Knowledge
This will output the formatted currency value as โ$1,234.56โ. The โ:,.2fโ specifier inside the f-string formats the value as a float with two decimal places and comma as the thousands separator. In this simplified guide, we explored different methods to format currency values in Python 3.
ZetCode
zetcode.com โบ python โบ fstring
Python f-string - formatting strings in Python with f-string
May 11, 2025 - Beyond basic formatting, f-strings enable advanced operations such as inline calculations, function calls, and even conditional expressions. This versatility makes them suitable for a wide range of applications in Python development, from constructing log messages to formatting financial data.
Python Guides
pythonguides.com โบ format-decimal-places-in-python-using-f-strings
How To Format Decimal Places In Python Using F-Strings?
March 19, 2025 - As a developer working on numerous projects across the USA, I recently faced an issue where I needed to format currency values with a specific number of decimal places for our financial reports. After researching various string formatting techniques, I found that using f-strings is an efficient and readable way to format decimal places. I will help you learn how to format decimal places in Python using f-strings in this tutorial with examples.
AskPython
askpython.com โบ home โบ fixed digits after decimal with f-string
Fixed digits after decimal with F-string - AskPython
May 31, 2023 - Letโs see the example to understand the working of the f-string model. ... In this syntax, the value contains the number with a decimal point. After โ.โ, we need to define the number of fixed digits we want to print after the decimal point, followed by the โfโ letter. Value = 'Askpython' print(f"you can learn Python from {Value}.com")
Tutorial Reference
tutorialreference.com โบ python โบ examples โบ faq โบ python-how-to-format-number-with-separator-for-thousands-and-currency
How to Format Numbers with Thousands Separators and Currency in Python | Tutorial Reference
This guide explores various methods in Python to format numbers with thousands separators and as currency, using f-strings, str.format(), and the locale module.
PyPI
pypi.org โบ project โบ multicurrency
multicurrency ยท PyPI
March 26, 2021 - # Using the `f-string` method >>> from multicurrency import Euro >>> euro = Euro(1000000*(1/7)) >>> f'{euro:4%a}' '142.857,1429' Some more examples of the Currency formatting feature usage (using the f-string method):
ยป pip install multicurrency
Version ย 2.1.0
Repository ย https://github.com/fscm/multicurrency
Homepage ย https://github.com/fscm//multicurrency
Reddit
reddit.com โบ r/learnpython โบ how to format money, so 100 becomes 1.00, not 100.00, 1000 becomes 10.00, not 1,000.00
r/learnpython on Reddit: How to format money, so 100 becomes 1.00, not 100.00, 1000 becomes 10.00, not 1,000.00
January 4, 2019 -
I am trying to write a small program with stripe API to get the charges, and I don't have to log in to the dashboard often. While I can get all data, stripe outputs the money unformatted without any decimals.
"data": [ { "amount": 6880,
but this is $68.80 is it possible I can convert the 6880 into $68.80? here is their API
Top answer 1 of 4
9
Divide the amount by 100, and then use format (or f-strings from Python 3.6+): amount = 6880 '${:,.2f}'.format(amount/100) # '$68.80'
2 of 4
6
For money, I recommend using the decimal module, to avoid floating-point number-rounding issues. Decimals can be built from ints, floats, or strings. I recommend using ints (integers) or strings to build the decimals, as they will be exactly as precise as the original value suggests. In this case, the API appears to be providing either an int (6880) or a string ("6880"), so that's good. An example from the decimal documentation to illustrate the difference between converting a string and converting a float: Decimal('3.14') # truly decimal 3.14 Decimal(3.14) # floating point is 3.140000000000000124344978758017532527446746826171875 Example code: from decimal import * def cents_to_dollars(cents = None,prefix='$'): if cents is None: dollar_string = prefix + '0.00' else: dollar_amount = (decimal(int(cents)) / decimal('100.00')).quantize(Decimal('0.01')) # used quantize to ensure 2 decimal places. Now just prepend the prefix. dollar_string = prefix + str(dollar_amount) return(dollar_string)