-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCvt.cpp
115 lines (86 loc) · 2.15 KB
/
Cvt.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "stdafx.h"
#include "Cvt.h"
namespace Easy {
COleDateTime Cvt::ToDateTime( CString sDateTime )
{
COleDateTime dt;
return dt.ParseDateTime(sDateTime) ? dt : COleDateTime(0, 0, 0, 0, 0, 0);
}
long Cvt::ToNumber( CString sNumber, int nRadix )
{
long dwNumber = _tcstoul(sNumber.GetBuffer(), NULL, nRadix);
sNumber.ReleaseBuffer();
return dwNumber;
}
double Cvt::ToNumber( CString sNumber )
{
return _ttof(sNumber);
}
CString Cvt::ToString( bool bValue, CString sTrue/*=_T("1")*/, CString sFalse/*=_T("1")*/ )
{
return bValue ? sTrue : sFalse;
}
CString Cvt::ToString( int nValue, bool bHex/*=false*/ )
{
CString sValue = _T("");
sValue.Format(bHex ? _T("%x") : _T("%d"), nValue);
return sValue;
}
CString Cvt::ToString( long nValue, bool bHex/*=false*/ )
{
CString sValue = _T("");
sValue.Format(bHex ? _T("%x") : _T("%ld"), nValue);
return sValue;
}
CString Cvt::ToString( UINT nValue, bool bHex/*=false*/ )
{
CString sValue = _T("");
sValue.Format(bHex ? _T("%x") : _T("%u"), nValue);
return sValue;
}
CString Cvt::ToString( DWORD dwValue, bool bHex/*=false*/ )
{
CString sValue = _T("");
sValue.Format(bHex ? _T("%x") : _T("%u"), dwValue);
return sValue;
}
CString Cvt::ToString( float fValue, int nPrecision/*=0*/ )
{
CString sValue = _T("");
CString sFormat = _T("%f");
if(nPrecision > 0)
{
sFormat.Format(_T("%%0.%df"), nPrecision);
}
sValue.Format(sFormat, fValue);
return sValue;
}
CString Cvt::ToString( double fValue, int nPrecision/*=0*/ )
{
CString sValue = _T("");
CString sFormat = _T("%f");
if(nPrecision > 0)
{
sFormat.Format(_T("%%0.%df"), nPrecision);
}
sValue.Format(sFormat, fValue);
return sValue;
}
CString Cvt::ToString( COleDateTime date )
{
CString sValue = _T("");
sValue.Format(_T("%d-%02d-%02d %02d:%02d:%02d"), date.GetYear(),
date.GetMonth(), date.GetDay(), date.GetHour(), date.GetMinute(), date.GetSecond());
return sValue;
}
CString Cvt::ToString( const wchar_t* pszFormat, ... )
{
ASSERT(pszFormat && *pszFormat);
wchar_t szMsg[1024];
va_list vargs;
va_start(vargs, pszFormat);
_vsnwprintf_s( szMsg, sizeof(szMsg) - 1, pszFormat, vargs);
va_end(vargs);
return CString(szMsg);
}
}