Python, print all floats to 2 decimal places in output

前端 未结 7 1124
野性不改
野性不改 2020-12-07 18:38

I need to output 4 different floats to two decimal places.

This is what I have:

print \'%.2f\' % var1,\'kg =\',\'%.2f\' % var2,\'lb =\',\'%.2f\' % va         


        
7条回答
  •  抹茶落季
    2020-12-07 18:51

    Well I would atleast clean it up as follows:

    print "%.2f kg = %.2f lb = %.2f gal = %.2f l" % (var1, var2, var3, var4)
    

提交回复
热议问题