Answers for "format string decimal places python d string"

0

python format decimal

# 2.6 python  and newer and python 3.x
# Put desired number of decimal by changing the number inside {:.2f} bellow;
print(' {:.2f}'.format(71.428571))
71.43
# 2.6 python and older
# Put desired number of decimal by changing the number inside '%.2f' bellow;
print('%.2f'%(71.428571))
71.43
Posted by: Guest on July-29-2021
0

format string to 2 decimal places python

num = 123.4567
print(round(num, 2))
#2 is the number of decimal digits (after the .)
Posted by: Guest on November-08-2021

Code answers related to "format string decimal places python d string"

Python Answers by Framework

Browse Popular Code Answers by Language