Search code examples
pythonpython-3.xdecimaltext-formatting

Formatting commas with 2 decimals PYTHON


I am trying to format a number to have commas and two decimal points at the end of it like: 100,000.00

This is what I have tried, but it won't work because I can't use these number formats on each other because they require a number to be inputted into the format.

"{:,}".format("{:.2f}".format(grossPay[i]))

So if you have any ideas on how I can do that, I would greatly appreciate it :D


Solution

  • if you just want to format any number into commas for 1000 and 2 decimals, all you need to do in Python is:

    "{:,.2f}".format(grossPay[i])