找回密码
 立即注册
收起左侧

怎么把Qstring类型数组转为Double类型数组,望解答!!

2
回复
11044
查看
[复制链接]
累计签到:7 天
连续签到:1 天
来源: 2016-4-15 12:38:27 显示全部楼层 |阅读模式
2Qter豆
比如我定义了Qvector<QString>ts;  ts里面存有一些数据了,我怎么把这个数据转为double型。to.double,具体是怎么弄,还望知道的耐心解答下!!

最佳答案

查看完整内容

double QString::toDouble(bool * ok = 0) const Returns the string converted to a double value. Returns 0.0 if the conversion fails. If a conversion error occurs, *ok is set to false; otherwise *ok is set to true. QString str = "1234.56"; double val = str.toDouble(); // val == 1234.56 Warning: The QString content may only contain valid numerical characters which includes the plus/minus sign, the c ...
回复

使用道具 举报

尚未签到

2016-4-15 12:38:28 显示全部楼层
double QString::toDouble(bool * ok = 0) const
Returns the string converted to a double value.
Returns 0.0 if the conversion fails.
If a conversion error occurs, *ok is set to false; otherwise *ok is set to true.
QString str = "1234.56";
double val = str.toDouble();   // val == 1234.56
Warning: The QString content may only contain valid numerical characters which includes the plus/minus sign, the characters g and e used in scientific notation, and the decimal point. Including the unit or additional characters leads to a conversion error.
bool ok;
double d;

d = QString( "1234.56e-02" ).toDouble(&ok); // ok == true, d == 12.3456
The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toDouble()
d = QString( "1234,56" ).toDouble(&ok); // ok == false
d = QString( "1234.56" ).toDouble(&ok); // ok == true, d == 1234.56
For historical reasons, this function does not handle thousands group separators. If you need to convert such numbers, use QLocale::toDouble().
d = QString( "1,234,567.89" ).toDouble(&ok); // ok == false
d = QString( "1234567.89" ).toDouble(&ok); // ok == true
回复

使用道具 举报

累计签到:7 天
连续签到:1 天
2016-4-15 17:15:37 显示全部楼层
Joey_Chan 发表于 2016-4-15 14:41
double QString::toDouble(bool * ok = 0) const
Returns the string converted to a double value.
Return ...

已解决了,谢谢啦!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了