QT中将float数转换为QString类型

概述

直接上代码,下面是示例:

示例一

float up = 23.45;
QString str = QString::number(up ,'f',2);

示例二

float up = 23.45;
QString str = QString::asprintf("%.2f",up);

示例三

float up = 23.45;
QString str;
str = str.setNum(up,'f',2);

示例四

float up = 23.45;
QString str;
str = str.sprintf("%.2f",up);

你可能感兴趣的:(Qt,qt,float转QString)