-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon.hpp
38 lines (30 loc) · 973 Bytes
/
common.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef COMMON_HPP
#define COMMON_HPP
#include <QString>
namespace vfg {
namespace format {
enum class SuffixOption
{
IncludeSuffix,
ExcludeSuffix
};
template <class NumberType>
QString formatNumber(const NumberType number,
const SuffixOption suffixOpt = SuffixOption::IncludeSuffix) {
const auto KB = number / 1000.0;
if(KB / 1000.0 < 1.0) {
return QString("%1%2").arg(QString::number(KB, 'f', 2))
.arg(suffixOpt == SuffixOption::IncludeSuffix ? " KB" : "");
}
const auto MB = KB / 1000.0;
if(MB / 1000.0 < 1.0) {
return QString("%1%2").arg(QString::number(MB, 'f', 2))
.arg(suffixOpt == SuffixOption::IncludeSuffix ? " MB" : "");
}
const auto GB = MB / 1000.0;
return QString("%1%2").arg(QString::number(GB, 'f', 2))
.arg(suffixOpt == SuffixOption::IncludeSuffix ? " GB" : "");
}
} // namespace format
} // namespace vfg
#endif // COMMON_HPP