user5802211
user5802211

Reputation: 197

Python: How to round the float value to 1.20 instead of 1.2

I found that if I use round function to some float values, it is OK to round to two decimals, but sometimes, for example, round(myvalu, 2) it will return 1.2 instead of 1.20, but actually I want every returned value is rounded to two decimals, i.e. 1.20 instead of 1.2. What should I do?

Upvotes: 0

Views: 1011

Answers (1)

Nikhil Kothari
Nikhil Kothari

Reputation: 5225

That's something you'd do when displaying the number.

Try

'%.2f' % num

Upvotes: 1

Related Questions