|
发表于 2020-7-31 00:30:01
|
显示全部楼层
昨天用vc做的
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('零'))
{
break;
}
else
{
sTemp.Insert(0, _T("零"));
}
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("肆"));
break;
case _T('5'):
sTemp.Insert(0, _T("伍"));
break;
case _T('6'):
sTemp.Insert(0, _T("陆"));
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('零'))
{
sTemp.Insert(1, _T("拾"));
}
break;
case 2:
if (sTemp != _T("") && sTemp.GetAt(0) != _T('零'))
{
sTemp.Insert(1, _T("佰"));
}
break;
case 3:
if (sTemp != _T("") && sTemp.GetAt(0) != _T('零'))
{
sTemp.Insert(1, _T("仟"));
}
break;
default:
break;
}
}
if (tcUnit != (TCHAR)0 && sTemp!= _T(""))
{
sNum->Insert(0,tcUnit);
}
else
{
if (tcUnit == _T('亿'))
{
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("您的输入错误!"));
return;
}
for (int i = 0; i<t; i++)
{
TCHAR tc = m_sNum.GetAt(i);
if (!_istdigit(tc))
{
MessageBox(_T("请输入数字!"));
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('万'));
}
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('万'));
CString hM;
hM = m_sNum.Left(m_sNum.GetLength() - 8);
AddStr (hM, &sNum, _T('亿'));
}
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('万'));
CString hM;
hM = m_sNum.Mid(m_sNum.GetLength()-12, 4);
AddStr (hM, &sNum, _T('亿'));
CString mHM;
mHM = m_sNum.Left(m_sNum.GetLength() - 12);
AddStr (mHM, &sNum, _T('万'));
}
if (sNum.GetAt(0)==_T('零'))
{
sNum.Delete(0);
}
m_sRead = sNum;
UpdateData(FALSE);
}
|
|