blob: 6349c97f013196d069348478b98a6427f389cad7 (
plain)
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
|
#include "StdAfx.h"
#include "UT2Utils.h"
/*static*/ unsigned int UT2Utils::Float2Int(float inValue) {
unsigned int result = 0;
if (inValue > 0.0f) {
result = inValue;
unsigned int decimal = (inValue - result) * 10.0f;
if (decimal > 0 && Randomize(10) < decimal)
result++;
}
return result;
}
/*static*/ void UT2Utils::GetRoomNumberString(int inNumber, CString& outStr) {
outStr.Format("%d", inNumber);
if (outStr.GetAt(0) == '-')
outStr.SetAt(0, 'B');
}
/*static*/ void UT2Utils::GetHourMinute(int inValue, int& outHour, int& outMinute) {
outHour = inValue / 60;
outMinute = inValue % 60;
}
/*static*/ void UT2Utils::GetMonetaryString(int inValue, CString& outStr) {
BOOL isNegative = false;
if (inValue < 0) {
isNegative = true;
inValue = -inValue;
}
outStr.Format("%d", inValue);
int len = outStr.GetLength();
if (len > 3) {
int numExtraDigits = len % 3;
int numGroups = len / 3;
if (numExtraDigits == 0) {
numExtraDigits = 3;
numGroups--;
}
for (int i = 0; i < numGroups; i++) {
int offset = numExtraDigits + (i * 3) + i;
outStr = outStr.Left(offset) + "," + outStr.Mid(offset);
}
}
if (isNegative)
outStr = "-" + outStr;
}
|