Answers for "python format float number of decimals"

3

python format only 1 decimal place

>>> "{0:0.1f}".format(45.34531)
'45.3'
Posted by: Guest on August-02-2020
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

Code answers related to "python format float number of decimals"

Python Answers by Framework

Browse Popular Code Answers by Language