博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MFC编写的人民币大小写转换
阅读量:4078 次
发布时间:2019-05-25

本文共 3301 字,大约阅读时间需要 11 分钟。

最近在学习MFC,编写了个金额由小写到大写的转换,全部代码如下:
/************************************************************************//* 对阿拉伯数组转换成中文数字                                                                     *//************************************************************************/CString CToChineseDlg::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;}void CToChineseDlg::OnBnClickedButton1(){	// 先判断是否有小数点	CString strSource, strDotAfter, strResult;	GetDlgItem(IDC_EDIT_SOURCE)->GetWindowText(strSource);	strDotAfter = this->GetDotAfterLength(strSource);	int iAllLength = strSource.GetLength();	int iDotAfterLength = strDotAfter.GetLength();	if(iDotAfterLength == 0)	{		if(iAllLength > 12)		{			MessageBox(L"输入的数字过长,不要超过12位", L"提示");		}		else		{			strResult = this->ChangeMoney(strSource);			GetDlgItem(IDC_EDIT_RESULT)->SetWindowText(strResult);		}	}	else	{		if(iAllLength - iDotAfterLength - 1 > 12)		{			MessageBox(L"输入的数字整数部分过长,不要超过12位", L"提示");			}		else if(iDotAfterLength > 2)		{			MessageBox(L"输入的数字小数点后面过长,不要超过2位", L"提示");			}		else		{			CString strDotBefore = strSource.Left(iAllLength - iDotAfterLength - 1);			strResult = this->ChangeMoney(strDotBefore);			// 再来计算小数点后的,这个简单不需要在封装函数了			for (int i = 0; i < iDotAfterLength; i++)			{				CString strUnit("");				CString strTemp = strDotAfter.Left(1);				strTemp = this->ToChineseLetter(strTemp);				strDotAfter = strDotAfter.Mid(1);				switch (i)				{				case 0:					strUnit = "角";break;				case 1:					strUnit = "分";break;				}				strResult += strTemp + strUnit;			}			GetDlgItem(IDC_EDIT_RESULT)->SetWindowText(strResult);		}	}}/************************************************************************//* 得到小数点后的字符串                                                                    *//************************************************************************/CString CToChineseDlg::GetDotAfterLength(CString strSource){	int iDotIndex = strSource.Find('.');	if(iDotIndex > -1)	{		return strSource.Mid(iDotIndex + 1);	}	return CString("");}/************************************************************************//* 转换                                                                     *//************************************************************************/CString CToChineseDlg::ChangeMoney(CString strSource){	CString strResult("");	int iLength = strSource.GetLength();	for (int i = 0; i < iLength; i++)	{		CString strUnit("");		// 获取右边第一个字符		CString strTemp = strSource.Right(1);		strSource = strSource.Left(strSource.GetLength() - 1);		// 得到中文		strTemp = this->ToChineseLetter(strTemp);		// 得到单位		switch (i)		{		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;		}		// 拼接起来		strResult = strTemp + strUnit + strResult;	}	return strResult;}

 

 效果图如下:

 

一下效果图是别处使用的。。

转载地址:http://woini.baihongyu.com/

你可能感兴趣的文章
FTP的命令
查看>>
CentOS操作系统下安装yum的方法
查看>>
ping 报name or service not known
查看>>
FTP 常见问题
查看>>
zookeeper单机集群安装
查看>>
do_generic_file_read()函数
查看>>
Python学习笔记之数据类型
查看>>
Python学习笔记之特点
查看>>
shell 快捷键
查看>>
VIM滚屏操作
查看>>
EMC 2014存储布局及十大新技术要点
查看>>
linux内核内存管理(zone_dma zone_normal zone_highmem)
查看>>
将file文件内容转成字符串
查看>>
循环队列---数据结构和算法
查看>>
优先级队列-数据结构和算法
查看>>
链接点--数据结构和算法
查看>>
servlet中请求转发(forword)与重定向(sendredirect)的区别
查看>>
Spring4的IoC和DI的区别
查看>>
springcloud 的eureka服务注册demo
查看>>
eureka-client.properties文件配置
查看>>