[英]python qt float precision from boost-python submodule
I have made a cpp submodule with boost-python for my PyQt program that among others extracts some data from a zip data file. 我为我的PyQt程序制作了带有boost-python的cpp子模块,该模块除其他外从zip数据文件中提取一些数据。
It works fine when testing it in python: 在python中测试时,它可以正常工作:
import BPcmods
BPzip = BPcmods.BPzip()
BPzip.open("diagnostics/p25-dev.zip")
l=BPzip.getPfilenames()
t=BPzip.getTempArray([l[1][4],l[1][3]],40.)
print(t[11][:10])
>> [40.1, 40.44, 40.78, 41.11, 41.44, 41.77, 41.77, 42.09, 42.41, 42.73]
if I put the same code in the start of my main part, it also gives the same data, but if I put the code right after I call 如果我在主体部分的开头放了相同的代码,它也提供了相同的数据,但是如果我在调用之后立即放了代码
main.app = QtGui.QApplication(sys.argv)
It suddenly yields: 它突然产生:
[40.0, 40.0, 40.0, 41.0, 41.0, 41.0, 41.0, 42.0, 42.0, 42.0]
Why?? 为什么?? what happened?
发生了什么? The numbers are still floats, but suddenly they have been rounded to nearest integer?!?
数字仍然是浮点数,但突然将它们四舍五入为最接近的整数?
Well it was related to using std::stod to convert my strings of data from my datafile to doubles. 好吧,这与使用std :: stod将我的数据字符串从数据文件转换为双精度有关。 I don't know why, but changing to:
我不知道为什么,但改为:
boost::algorithm::trim(s);
double val = boost::lexical_cast<double>(s);
made it work as it was supposed to, also in pyqt. 使其在pyqt中按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.