当前位置: 动力学知识库 > 问答 > 编程问答 >

rounding - 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?

网友答案:

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

Try

'%.2f' % num
分享给朋友:
您可能感兴趣的文章:
随机阅读: