How to Format Number with Four Decimals in Python


In this example we will show how to format the number to be displayed as a number with four decimals in Python.

Source Code

import math

print('PI:', math.pi)

print('PI: {:.4f}'.format(math.pi))

Output:

PI: 3.141592653589793
PI: 3.1416
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments