Formatting Numbers

Want to learn more? I recommend these Python books: Python for Data Analysis, Python Data Science Handbook, and Introduction to Machine Learning with Python.

Create A Long Number

annual_revenue = 9282904.9282872782

Format Number

# Format rounded to two decimal places
format(annual_revenue, '0.2f')
'9282904.93'
# Format with commas and  rounded to one decimal place
format(annual_revenue, '0,.1f')
'9,282,904.9'
# Format as scientific notation
format(annual_revenue, 'e')
'9.282905e+06'
# Format as scientific notation rounded to two deciminals
format(annual_revenue, '0.2E')
'9.28E+06'