spark-qt-research/Components/MultiplethreadDownload/utils.cpp

22 lines
413 B
C++
Raw Normal View History

2020-10-25 20:03:47 +08:00
#include "utils.h"
#include <QStringList>
#include <QLocale>
QString Utils::sizeFormat(qint64 bytes)
{
qreal size = bytes;
QStringList list;
list << "KB" << "MB" << "GB" << "TB";
QStringListIterator i(list);
QString unit("bytes");
while (size >= 1024.0 && i.hasNext()) {
unit = i.next();
size /= 1024.0;
}
return QString().setNum(size, 'f', 2) + " " + unit;
}