1.qAbs
qAbs:原型为 T qAbs(const T &value) 返回输入参数对应类型的绝对值,其中T为输入参数类型,也就是可以返回多种类型(int,float,double型)
代码示例:
int d = -1;
float b = -3.14;
double c = -4.36;
int a_temp = 0;
float b_temp = 0;
double c_temp = 0;
a_temp = qAbs(d);
b_temp = qAbs(b);
c_temp = qAbs(c);
qDebug() << "a_temp = " << a_temp << "b_temp = " << b_temp << "c_temp == " << c_temp;
结果:
参考:Qt 绝对值 qAbs()、abs() 与fabs() - 一杯清酒邀明月 - 博客园 (cnblogs.com)
2.qRound
qRound为四舍五入函数
示例:
float e = 3.4;
float f = 4.6;
int e_temp = qRound(e);
int f_temp = qRound(f);
qDebug() << "e_temp = " << e_temp << "f_temp = " << f_temp ;
结果: