当前位置:网站首页>Qt: judge whether the string is in numeric format

Qt: judge whether the string is in numeric format

2022-06-24 11:13:00 Xiaoying Information Technology Service Department

Qt Development , You need to implement a basic function , Determine whether a string can be converted to a number , for example :

123.45 Can be converted into numbers ;

123.BC Can't be converted to numbers ;

Qt How to judge in ? Do some research , Found the answer :

bool isNum;
QString a = "123.56";
a.toDouble(&isNum);
qDebug() << "a isNum: " << isNum;

QString b = "123.BC";
b.toDouble(&isNum);
qDebug() << "b isNum: " << isNum;

Output :

Reference resources :

https://doc.qt.io/qt-5/qstring.html#toDouble

原网站

版权声明
本文为[Xiaoying Information Technology Service Department]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206240951354444.html