QString str = QString("移动(%1 mm)").arg(L);
double L = 1.34567;
请问各位大神,怎么使str在Label显示时小数点后只有两位数字,菜鸟一枚,求各位大神指教。
QString::number(L, 'f', 2)
QString QString::number(double n, char format = 'g', int precision = 6) [static]
Returns a string equivalent of the number n, formatted according to the specified format and precision. See Argument Formats for details.
Unlike QLocale::toString(), this function does not honor the user's locale settings.
可以把它转为字符串,对字符串进行位数限制处理。楼上的API可以借用,非常有效。