python - format float to decimal in pyQt

2019-09-11 02:17发布

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条回答
太酷不给撩
2楼-- · 2019-09-11 02:37

You could do

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

Documentation

查看更多
登录 后发表回答