python - format float to decimal in pyQt

你说的曾经没有我的故事 提交于 2019-12-12 04:18:27

问题


I have this code in pyQt:

calculation = day + night self.label.setText(repr(calculation * 30)

and I can see result as: 3.7446232 but I would like to see as 3.74.

Could you please point me to how to set decimal to 2. Should I use .format(round(calculation * 30) or for pyQt is different way to do this?

Regards


回答1:


You could do

self.label.setText("%.2f", % (calculation * 30))

Documentation



来源:https://stackoverflow.com/questions/34814941/python-format-float-to-decimal-in-pyqt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!