|
Made with vc yesterday
void CNumDlg::AddStr(CString sStr, CString *sNum, TCHAR tcUnit)
{
int t = sStr.GetLength();
CString sTemp = _T("");
for (int i=0; i<t; i++)
{
TCHAR tcTemp = sStr.GetAt(t-1-i);
switch (tcTemp)
{
case _T('0'):
if (sTemp == _T("") || sTemp.GetAt(0) == _T('zero'))
{
break;
}
else
{
sTemp.Insert(0, _T("zero"));
}
break;
case _T('1'):
sTemp.Insert(0, _T("一"));
break;
case _T('2'):
sTemp.Insert(0, _T("贰"));
break;
case _T('3'):
sTemp.Insert(0, _T("三"));
break;
case _T('4'):
sTemp.Insert(0, _T("4"));
break;
case _T('5'):
sTemp.Insert(0, _T("五"));
break;
case _T('6'):
sTemp.Insert(0, _T("Lu"));
break;
case _T('7'):
sTemp.Insert(0, _T("柒"));
break;
case _T('8'):
sTemp.Insert(0, _T("捌"));
break;
case _T('9'):
sTemp.Insert(0, _T("玖"));
break;
default:
break;
}
switch(i)
{
case 0:
break;
case 1:
if (sTemp != _T("")&&sTemp.GetAt(0) != _T('zero'))
{
sTemp.Insert(1, _T("take"));
}
break;
case 2:
if (sTemp != _T("")&&sTemp.GetAt(0) != _T('zero'))
{
sTemp.Insert(1, _T("百"));
}
break;
case 3:
if (sTemp != _T("")&&sTemp.GetAt(0) != _T('zero'))
{
sTemp.Insert(1, _T("千"));
}
break;
default:
break;
}
}
if (tcUnit != (TCHAR)0&&sTemp!= _T(""))
{
sNum->Insert(0,tcUnit);
}
else
{
if (tcUnit == _T('billion'))
{
sNum->Insert(0,tcUnit);
}
}
sNum->Insert(0,sTemp);
}
void CNumDlg::OnRead()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CString sNum = _T("");
int t = m_sNum.GetLength();
while (true)
{
if (t>0&&m_sNum.GetAt(0) == _T('0'))
{
m_sNum.Delete(0);
t--;
continue;
}
break;
}
if (t<=0)
{
MessageBox(_T("Your input is wrong!"));
return;
}
for (int i = 0; i<t; i++)
{
TCHAR tc = m_sNum.GetAt(i);
if (!_istdigit(tc))
{
MessageBox(_T("Please enter a number!"));
return;
}
}
if (t<=4)
{
AddStr (m_sNum,&sNum, (TCHAR)0);
}
if (t>4&&t<=8)
{
CString sTh;
sTh = m_sNum.Right(4);
AddStr (sTh,&sNum, (TCHAR)0);
CString sM;
sM = m_sNum.Left(m_sNum.GetLength()-4);
AddStr (sM,&sNum, _T('10,000'));
}
if (t>8&&t<=12)
{
CString sTh;
sTh = m_sNum.Right(4);
AddStr (sTh,&sNum, (TCHAR)0);
CString sM;
sM = m_sNum.Mid(m_sNum.GetLength()-8, 4);
AddStr (sM,&sNum, _T('10,000'));
CString hM;
hM = m_sNum.Left(m_sNum.GetLength()-8);
AddStr (hM,&sNum, _T('billion'));
}
if (t>12&&t<=16)
{
CString sTh;
sTh = m_sNum.Right(4);
AddStr (sTh,&sNum, (TCHAR)0);
CString sM;
sM = m_sNum.Mid(m_sNum.GetLength()-8, 4);
AddStr (sM,&sNum, _T('10,000'));
CString hM;
hM = m_sNum.Mid(m_sNum.GetLength()-12, 4);
AddStr (hM,&sNum, _T('billion'));
CString mHM;
mHM = m_sNum.Left(m_sNum.GetLength()-12);
AddStr (mHM,&sNum, _T('10,000'));
}
if (sNum.GetAt(0)==_T('zero'))
{
sNum.Delete(0);
}
m_sRead = sNum;
UpdateData(FALSE);
} |
|