C# 人民币(RMB)转化为大写字母
2007-12-21 10:02
417 查看
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public class ToChineseValue
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
private enum chineseChar...{零,壹,贰,叁,肆,伍,陆,柒,捌,玖};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
private enum charValue...{个=1,十,百,千}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
private enum c...{元=1,万,亿,兆};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
private enum afterPoint...{角,分};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public ToChineseValue()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// TODO: 在此处添加构造函数逻辑
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public string toChineseChar(decimal d)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
decimal flag=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(d<0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
flag=d;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
d=-d;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string strChinese="";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string nextString="";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.Globalization.NumberFormatInfo fmat=new System.Globalization.NumberFormatInfo();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
fmat.CurrencyDecimalDigits=2;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
fmat.CurrencySymbol="";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
fmat.CurrencyGroupSizes =new int []...{4,4,4,4};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
fmat.CurrencyGroupSeparator=",";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string strx=d.ToString("c",fmat);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string []afterArray=strx.ToString() .Split ('.');
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char[] prePoint=afterArray[0].ToCharArray ();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char [] nextChar=afterArray[1].ToCharArray ();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(System.Convert .ToDecimal (afterArray[0].ToString ())==0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{ strChinese="";}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string [] str=afterArray[0].ToString().Split (',');
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int Num=str.Length ;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//交错数组用来放四个一组的数组
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
char[][]part=new char [Num][];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(int i=0;i<str.Length ;i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
part[i]=str[i].ToCharArray ();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(int i=0;i<Num;i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(int j=0;j<part[i].Length;j++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//用枚举完成汉字的转换
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strChinese+=((chineseChar)int.Parse (part[i][j].ToString ())).ToString ();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//用枚举完成单位: 个 十 百 千
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strChinese+=((charValue)(part[i].Length-j)).ToString();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//以下为处理元 万 亿 兆
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strChinese+=((c)(part.Length-i)).ToString();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//处理点号后面的小数部分
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(System.Convert.ToDecimal(afterArray[1].ToString ())==0&&System.Convert.ToDecimal(afterArray [0].ToString ())!=0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextString="整";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(int i=0;i<2;i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int t=int.Parse (nextChar[i].ToString ());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextString+=((chineseChar)int.Parse (nextChar[i].ToString ())).ToString ();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextString+=((afterPoint)(i)).ToString();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(t==0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
StringBuilder str=new StringBuilder(nextString);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextString=str.Replace ("零零","零").ToString ();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
nextString=str.Replace ("零角零分","零元").ToString ();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
StringBuilder sb=new StringBuilder(strChinese);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(int i=0;i<4;i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strChinese=sb.Replace ("个","").ToString ();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strChinese=sb.Replace ("零元","元").ToString ();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strChinese=sb.Replace ("零万","万").ToString ();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strChinese=sb.Replace ("亿万","亿").ToString ();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strChinese=sb.Replace ("零亿","亿").ToString ();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strChinese=sb.Replace ("零十","零").ToString ();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strChinese=sb.Replace ("零百","零").ToString ();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strChinese=sb.Replace ("零千","零").ToString ();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strChinese=sb.Replace ("零零","零").ToString ();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
strChinese=sb.Replace ("零角零分","整").ToString ();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(flag>=0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return strChinese+nextString;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return "负"+strChinese+nextString;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
相关文章推荐
- 数字人民币(RMB)转化为大写字母
- 将人民币的数字表示转化成大写表示(C#版)
- 将人民币的数字表示转化成大写表示(C#版)
- 将人民币的数字表示转化成大写表示(C#版)
- 将人民币的数字表示转化成大写表示(C#版)
- 将人民币的数字表示转化成大写表示(C#版) (转)
- 将人民币的数字表示转化成大写表示(C#版)
- C#人民币大小写转化
- 用C#将输入的小写字母转化为大写字母
- 将一串数字转化为中文字符串,使用 C# 将数字转换成大写人民币 (例如:用户输入2300,系统就会显示两千三百元 )
- C# double float int string 与 byte数组 相互转化
- [转]c#拼音汉字转化
- c# 虚拟路径转化为物理路径
- C#把datetime类型的日期转化成其他格式方法总结
- C# byte[]和文件FileStream相互转化
- 【求助】xmlhttp.responseStream怎么转化成C#能引用的数据流
- C#将照片或图片转化为byte[]存入数据库,从数据库中读照片
- C# 字符串重编码——任意字符串转化为全字母串
- C# 将正方形头像转化成圆形头像(例如:qq头像)
- c#去html标志,对字符串保留数字小数点,有中文的日期转化等特殊数据处理