-
Notifications
You must be signed in to change notification settings - Fork 0
/
intString.cpp
85 lines (75 loc) · 1.78 KB
/
intString.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
74
75
76
77
78
79
80
81
82
83
84
85
#include "implementation.h"
#include <QString>
string intToString(int i) {
ostringstream os;
os << i;
return os.str();
}
string intToString(ll i) {
if (!i) return string("0");
ll t = i / 10;
int cnt = 0;
while (t) {
t /= 1000;
cnt++;
}
cnt--;
if (cnt <= 0) return intToString((int)i);
ll divisor = pow(1000, cnt) / 100;
t = i / divisor;
double tt = (double)t / 100;
string ret;
ostringstream os;
os << fixed << setprecision(2) << tt;
ret = os.str();
switch (cnt) {
case 1: ret += "k"; break; //10^3
case 2: ret += "M"; break; //10^6
case 3: ret += "G"; break; //10^9
case 4: ret += "T"; break; //10^12
case 5: ret += "P"; break; //10^15
case 6: ret += "E"; break; //10^18
}
return ret;
}
string longToString(ll i) {
ostringstream os;
os << i;
return os.str();
}
string numToString(ll i) {
int base = 5;
string t = longToString(i);
string ret = "";
while ((int)t.length() > base) {
ret += t.substr(0, base) + '\n';
t = t.substr(base);
}
ret += t;
return ret;
}
int stringToInt(string s) {
istringstream is(s);
int t;
is >> t;
return t;
}
QString intToQString(int i) {
return QString::fromLocal8Bit(intToString(i).data());
}
QString intToQString(ll i) {
return QString::fromLocal8Bit(intToString(i).data());
}
QString longToQString(ll i) {
return QString::fromLocal8Bit(longToString(i).data());
}
QString numToQString(ll i) {
if (i == 4294967296) return "∞";
return QString::fromLocal8Bit(numToString(i).data());
}
pair<bool, int> isNumber(QString s) //返回输入的是否是数字,以及数字的数值
{
bool number;
int val = s.toInt(&number);
return make_pair(number, val);
}