21

I have an issue in printing a float number. I tried:

a = 2
c = 4
print (str(c/a).format(1.6))

Output:

2.0

Required Output:

2.000000

How can I print up to 6 decimal places?

miradulo
  • 28,857
  • 6
  • 80
  • 93
Rohith
  • 1,008
  • 3
  • 8
  • 19
  • 1
    In your case, `print('%.6f' % 2)`. or better yet `print(str.format('{0:.6f}', 2))` – miradulo Jul 01 '16 at 09:11
  • Your question is a duplicate. Look at how `str.format` is used in the answers to the other question and read the documentation. – Bakuriu Jul 01 '16 at 09:17

1 Answers1

38

This can be accomplished by:

print("{:.6f}".format(your value here));
user3206656
  • 416
  • 4
  • 3