PYTHON
format to 2 or n decimal places python
num = 123.4567
formatted_num = '{0:.2f}'.format(num) # to 2 decimal places
# formatted_num = '123.46'
python 2 decimal places
print(format(432.456, ".2f"))
>> 432.45
print(format(321,".2f"))
>> 321.00
python print only 2 decimals
a = 1.2138568
print(f'{a:.2f}')
print two digits after decimal python
float = 2.154327
format_float = "{:.2f}".format(float)
print(format_float)
printing with format float to 2 decimal places python
formatted_float = "{:.2f}".format(a_float)
python 2 decimal places format
>>> foobar = 3.141592
>>> print(f'My number is {foobar:.2f} - look at the nice rounding!')
My number is 3.14 - look at the nice rounding!
how to print answer 2 decimal places in python 3
print("{0:.2f}".format(sum(student_marks[query_name])/3))
print 2 decimal places python
print("{0:.2f}".format(sum(query_marks)/len(query_marks)))
python print 2 decimal places
# this will print up to digits after decimal
print("%.2f" % (70/105))
python print with 2 decimals
# round a value to 2 decimal points
value_to_print = 123.456
print(f'value is {round(value_to_print, 2)}')
# prints: value is 123.46
how print 2 decimal in python
for i in range(10):
j=i*0.1
print('%0.2f' %j)
python 2 decimal places format