如何使浮点值在Python中显示.00而不是.0? [英] How to make float values in Python display .00 instead of .0?
本文介绍了如何使浮点值在Python中显示.00而不是.0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一个简单的问题,对不起,无法解决。我有一些由
float(STRING)
构成的数字,它们显示为xxx.0,但如果它们确实是整数,我希望它们以.00结尾。我该怎么办?
Simple question, sorry I can;t figure this out. I have some numbers that are made by float(STRING) and they are displayed as xxx.0, but I want them to end in .00 if it is indeed a whole number. How would I do this?
谢谢!
编辑:
float的Python说法没有cal'format()'
Python saiys that float doesn't have a cal 'format()'
推荐答案
>>> '%.2f' % 2.0
'2.00'
这篇关于如何使浮点值在Python中显示.00而不是.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文