Python - Number Formatting
Python - Number Formatting
You can format numbers using the format specifier given below:
Type Meaning
d Decimal integer
c Corresponding Unicode character
b Binary format
o Octal format
x Hexadecimal format (lower case)
X Hexadecimal format (upper case)
e Exponential notation. (lowercase e)
E Exponential notation (uppercase E)
f Displays fixed point number (Default: 6)
F Same as 'f'. Except displays 'inf' as 'INF' and 'nan' as 'NAN'
g General format. Rounds number to p significant digits. (Default
precision: 6)
G Same as 'g'. Except switches to 'E' if the number is large.
% Percentage. Multiples by 100 and puts % at the end.
Simple number formatting
# integer arguments
print("The number is:{:d}".format(123))
#123
# float arguments
print("The float number is:
{:f}".format(123.4567898)) #123.4567898