这是一个将金额小写转为大写的代码,在网上看到有类似的,但都有点不太合适就自己改了一个版本供大家参考
///************************************************************************/
///* 转换 */
///************************************************************************/
CString Show_Bill::ChangeMoney(CString strSource)
{
CString strResult("");
int iLength = strSource.GetLength();
//先填充整数部分
int front =strSource.ReverseFind('.');
int decimals=strSource.GetLength()-front;
int sdk_i=0;
if(front != -1)
{
for (int i = 0; i < iLength; i++)
{
CString strUnit("");
// 获取右边第一个字符
CString strTemp = strSource.Right(1);
strSource = strSource.Left(strSource.GetLength() - 1);
if(strTemp == '.')
{
continue;
}
//这里是小数未通过整数
if(sdk_i<decimals-1)
{
if(decimals >2)
{
if (sdk_i == 1)
{
strUnit = "角";
}
else if (sdk_i == 0)
{
strUnit = "分";
}
}
else
{
if (sdk_i == 1)
{
strUnit = "角";
}
else if (sdk_i == 0)
{
strUnit = "";
}
}
// 得到中文
strTemp = this->ToChineseLetter(strTemp);
//拼接起来
strResult = strTemp + strUnit + strResult;
sdk_i++;
continue;
}
// 得到中文
strTemp = this->ToChineseLetter(strTemp);
// 得到单位
switch (i-decimals)
{
case 0:
strUnit = "元";break;
case 1:
case 5:
case 9:
strUnit = "拾";break;
case 2:
case 6:
case 10:
strUnit = "百";break;
case 3:
case 7:
case 11:
strUnit = "千";break;
case 4:
strUnit = "万";break;
case 8:
strUnit = "亿";break;
}
if(strTemp != "零")
{
//拼接起来
strResult = strTemp + strUnit + strResult;
}
if(strUnit == "元" && strTemp == "零")
{
// 拼接起来
strResult =_T("元")+strResult;
}
}
}
return strResult;
}
///************************************************************************/
///* 对阿拉伯数组转换成中文数字 */
///************************************************************************/
CString Show_Bill::ToChineseLetter(CString strSourceLetter)
{
strSourceLetter.Replace(L"0", L"零");
strSourceLetter.Replace(L"1", L"壹");
strSourceLetter.Replace(L"2", L"贰");
strSourceLetter.Replace(L"3", L"叁");
strSourceLetter.Replace(L"4", L"肆");
strSourceLetter.Replace(L"5", L"伍");
strSourceLetter.Replace(L"6", L"陆");
strSourceLetter.Replace(L"7", L"柒");
strSourceLetter.Replace(L"8", L"捌");
strSourceLetter.Replace(L"9", L"玖");
return strSourceLetter;
}