-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormatNumber.cpp
77 lines (46 loc) · 992 Bytes
/
FormatNumber.cpp
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// FormatNumber.cpp
// Declares the functions for formatting numbers
#include "Globals.h"
#include "FormatNumber.h"
QString formatBigNumber(quint64 a_Number)
{
QString res("%1");
res = res.arg(a_Number);
// Insert spaces as a thousand-separator:
auto i = res.lastIndexOf('.');
if (i < 0)
{
i = res.length();
}
i -= 3;
while(i > 0)
{
res.insert(i, ' ');
i -= 3;
}
return res;
}
QString formatBigSignedNumber(qint64 a_Number)
{
if (a_Number >= 0)
{
return formatBigNumber(static_cast<quint64>(a_Number));
}
else
{
return QString("-") + formatBigNumber(static_cast<quint64>(-a_Number));
}
}
QString formatMemorySize(quint64 a_Size)
{
return formatBigNumber((a_Size + 1023) / 1024);
}
QString formatSignedMemorySize(qint64 a_Size)
{
if (a_Size >= 0)
{
return formatBigNumber(static_cast<quint64>((a_Size + 1023) / 1024));
}
a_Size = -a_Size;
return QString("-") + formatBigNumber(static_cast<quint64>((a_Size + 1023) / 1024));
}