Title: Formatting Numbers
Slug: formatting_numbers
Summary: Formatting Numbers Using Python.
Date: 2017-02-02 12:00
Category: Python
Tags: Basics
Authors: Chris Albon

Create A Long Number


In [1]:
annual_revenue = 9282904.9282872782

Format Number


In [2]:
# Format rounded to two decimal places
format(annual_revenue, '0.2f')


Out[2]:
'9282904.93'

In [3]:
# Format with commas and  rounded to one decimal place
format(annual_revenue, '0,.1f')


Out[3]:
'9,282,904.9'

In [4]:
# Format as scientific notation
format(annual_revenue, 'e')


Out[4]:
'9.282905e+06'

In [5]:
# Format as scientific notation rounded to two deciminals
format(annual_revenue, '0.2E')


Out[5]:
'9.28E+06'