python - 在 pyQt 中将浮点数格式化为十进制

python - format float to decimal in pyQt

我在 pyQt 中有这段代码:

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

我可以看到结果为:3.7446232,但我希望看到 3.74。

你能告诉我如何将小数设置为 2 吗?我应该使用 .format(round(calculation * 30) 或对于 pyQt 有不同的方法吗?

此致

你可以

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

Documentation

self.lineEdit_4.setText("%.2f"%(row[3]))