MFC中将金额小写转为大写

这是一个将金额小写转为大写的代码,在网上看到有类似的,但都有点不太合适就自己改了一个版本供大家参考

///************************************************************************/
///* 转换                                                                     */
///************************************************************************/
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;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值