显示文件大小的后缀

QString GPublicFunction::ConvertByteDisplay(qulonglong longsize)
{
	const double intStandard=1024;
	QStringList names;

	names << "B" << "KB" << "M" << "G"<<"TG";

	double dbsize=longsize;
	int count=0;
	while (dbsize>=intStandard)
	{
		dbsize=dbsize/intStandard;
		count++;
	}
	QString strResult=QString::number(dbsize)+names[count];
	if (count>names.count())
	{
		return QObject::tr("Too big");
	}
	return strResult;
}


 
 

你可能感兴趣的:(显示文件大小的后缀)