VCデジタルを人民元金額大文字に変換する簡単なアルゴリズム実現
1859 ワード
void CNumberToRMBDlg::OnButton1()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
int pos = m_szNumber.Find(_T("."));
CString szInteger, szFloat;
if (pos != -1)
{
szInteger = m_szNumber.Left(pos);
szFloat = m_szNumber.Mid(pos+1);
if (szFloat.GetLength() > 2)
{
szFloat = szFloat.Left(2);
}
}else{
szInteger = m_szNumber;
}
CString szNumberSeed = _T(" ");
CString szRMBSeed = _T(" ");
LPCTSTR lpInteger = (LPCTSTR)szInteger;
CString szRMB = _T("");
int iCount = 0;
for (int i= szInteger.GetLength() - 1; i > -1; i--)
{
char cNumber = lpInteger[i];
int nNumber = atoi(&cNumber);
szRMB = szNumberSeed.Mid(nNumber * 2, 2) + szRMBSeed.Mid(iCount * 2,2) + szRMB;
iCount++;
}
CString szRMBFloat = _T("");
LPCTSTR lpFloat = (LPCTSTR)szFloat;
if (szFloat.GetLength() > 0)
{
char cNumber = lpFloat[0];
int nNumber = atoi(&cNumber);
szRMB += szNumberSeed.Mid(nNumber * 2, 2) + _T(" ");
}
if (szFloat.GetLength() > 1)
{
char cNumber = lpFloat[1];
int nNumber = atoi(&cNumber);
szRMB += szNumberSeed.Mid(nNumber * 2, 2) + _T(" ");
}
m_szRMB = szRMB;
UpdateData(FALSE);
}
void CNumberToRMBDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CNumberToRMBDlg)
DDX_Text(pDX, IDC_EDIT_NUMBER, m_szNumber);
DDX_Text(pDX, IDC_EDIT_RMB, m_szRMB);
//}}AFX_DATA_MAP
}