0

When i use %f in print it dosent work properly like the format type.

my code is:

a=13
print('dfdsfds %2f'%a +"  {:.2f}".format(a))

the answer is:

dfdsfds 13.000000  13.00

and the %numf just shows 6 precision and it doesn't care what is the num. why this happens?

Joe Ferndz
  • 8,417
  • 2
  • 13
  • 33
Beryl Amend
  • 131
  • 1
  • 9

1 Answers1

1

It does work properly. You just wrote to a different format Strings. If you change it to this:

a=13
print('dfdsfds %.2f' % a + "  {:.2f}".format(a))

You will get the output:

dfdsfds 13.00  13.00
Tilo K
  • 26
  • 3