python格式化为pyQt中的十进制 [英] python - format float to decimal in pyQt

查看:199
本文介绍了python格式化为pyQt中的十进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在pyQt中有这样的代码:
$ b $ p $计算=天+夜
self.label.setText(repr(calculation * 30)



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

请问我可以如何设置小数点位数2.如果我使用
.format(round(calculate * 30)或for pyQt是不同的方式做到这一点?



问候

解决方案

可以做
$ b $ pre $ self.label.setText(%。2f,%(calculation * 30))

文档


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

解决方案

You could do

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

Documentation

这篇关于python格式化为pyQt中的十进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆