-2

val = 345.09874

now i want output like 345.10, 345.09 and 345.099 in python 2.7

Please help me.

Ramesh Puruganti
  • 101
  • 2
  • 2
  • 6
  • 1
    Please help us, and help yourself, by searching the damn site before posting. This question has been answered thousands of times across the Internet. – Jonathon Reinhart Mar 30 '15 at 10:14
  • 1
    possible duplicate of [how to round off a floating number in python](http://stackoverflow.com/questions/4518641/how-to-round-off-a-floating-number-in-python) – Justin Sane Mar 30 '15 at 10:18

2 Answers2

0

Just to encourage you I am providing the answer, but next time you should google first.

Use this:

print round(val,2)

Muhammad Bilal
  • 2,106
  • 1
  • 15
  • 24
0

I could get 2 out of 3 values using:

val = 345.09874
print("%.2f" % round(val,2)) #345.10
print("%.3f" % round(val,3)) #345.099

I dont know how to get the output with 345.09