c#实现人民币小写转大写(原)

       前段时间有个朋友在做一个关于金融的项目,提到金融中关于钱的小写转大写的问题,于是没事就演了一下,效果还不错,暂时还没有发现错误,如果你发现了,可以联系我哦,交流切磋下嘛,呵呵!
         
None.gifprivate readonly string _NumChinese="零壹贰叁肆伍陆柒捌玖";
None.gifprivate string GetNumCHN( decimal number )
ExpandedBlockStart.gif ContractedBlock.gif dot.gif{
InBlock.gif if ( Math.Abs( number ) < (decimal)0.01  )
InBlock.gif  return "零圆整";
InBlock.gif long y = Convert.ToInt64( Decimal.Truncate( number / 100000000 ) );
InBlock.gif long w = Convert.ToInt64( Decimal.Truncate( (number - y * 100000000)/10000 ) );
InBlock.gif long g = Convert.ToInt64( Decimal.Truncate( number % 10000 ) );
InBlock.gif long x = Convert.ToInt64( Decimal.Truncate( ( number - Decimal.Truncate( number ) ) * 100 ) ); 
InBlock.gif
InBlock.gif string re;
InBlock.gif if ( y < 1000 && y != 0 )
InBlock.gif  re = GetCHN( y ).Substring( 1 ) + "亿";
InBlock.gif else
InBlock.gif  re = GetCHN( y ); 
InBlock.gif
InBlock.gif if ( w != 0 )
ExpandedSubBlockStart.gif ContractedSubBlock.gif  dot.gif{
InBlock.gif  if ( re != "" )
InBlock.gif   re += GetCHN( w ) + "万";
InBlock.gif  else
InBlock.gif   re = GetCHN( w ).Substring( 1 );
ExpandedSubBlockEnd.gif } 
InBlock.gif
InBlock.gif if ( g != 0 )
ExpandedSubBlockStart.gif ContractedSubBlock.gif  dot.gif{
InBlock.gif  if ( re != "" )
InBlock.gif   re += GetCHN( g );
InBlock.gif  else
InBlock.gif   re = GetCHN( g ).Substring( 1 );
ExpandedSubBlockEnd.gif } 
InBlock.gif
InBlock.gif if ( re != "" )  //高位有数值
ExpandedSubBlockStart.gif ContractedSubBlock.gif  dot.gif{
InBlock.gif  if ( x == 0 ) //无小数位
InBlock.gif   re += "圆整";
InBlock.gif  else   //有小数位
InBlock.gif   re += "圆零" + GetFCHN( x );
ExpandedSubBlockEnd.gif }
InBlock.gif else    //高位无数值
ExpandedSubBlockStart.gif ContractedSubBlock.gif  dot.gif{
InBlock.gif  if ( x == 0 ) //无小数位
InBlock.gif   re += "零圆";
InBlock.gif  else   //有小数位
InBlock.gif   re += GetFCHN( x );
ExpandedSubBlockEnd.gif } 
InBlock.gif
InBlock.gif return re;
ExpandedBlockEnd.gif
None.gif
None.gifprivate string GetFCHN( long aa )
ExpandedBlockStart.gif ContractedBlock.gif dot.gif{
InBlock.gif string re = string.Empty;
InBlock.gif int x = Convert.ToInt32(aa % 10);  //分
InBlock.gif int y = Convert.ToInt32((aa - x)/10); //角 
InBlock.gif
InBlock.gif if ( y != 0 )
InBlock.gif  re = _NumChinese[y] + "角"; 
InBlock.gif
InBlock.gif if ( x != 0 )
InBlock.gif  re += _NumChinese[x] + "分"; 
InBlock.gif
InBlock.gif return re;
ExpandedBlockEnd.gif
None.gif
None.gifprivate string GetCHN( long aa )
ExpandedBlockStart.gif ContractedBlock.gif dot.gif{
InBlock.gif string re = string.Empty; 
InBlock.gif
InBlock.gif if ( aa == 0 )
InBlock.gif  return re; 
InBlock.gif
InBlock.gif int l1 = Convert.ToInt32( aa % 10 );
InBlock.gif int l2 = Convert.ToInt32( (aa - l1)/10 % 10 );
InBlock.gif int l3 = Convert.ToInt32( (aa - l1 - l2 * 10 )/100 % 10 );
InBlock.gif int l4 = Convert.ToInt32( Math.Floor( aa / 1000 ) ); 
InBlock.gif
InBlock.gif re = "零";
InBlock.gif if ( l4 == 0 )
ExpandedSubBlockStart.gif ContractedSubBlock.gif  dot.gif{
InBlock.gif  if ( re[re.Length-1] != '零' && l3 != 0 )
InBlock.gif   re += "零";
ExpandedSubBlockEnd.gif }
InBlock.gif else
InBlock.gif  re += _NumChinese[l4] + "仟"; 
InBlock.gif
InBlock.gif if ( l3 == 0 )
ExpandedSubBlockStart.gif ContractedSubBlock.gif  dot.gif{
InBlock.gif  if ( re[re.Length-1] != '零' && l2 != 0 )
InBlock.gif   re += "零";
ExpandedSubBlockEnd.gif }
InBlock.gif else
InBlock.gif  re += _NumChinese[l3] + "佰"; 
InBlock.gif
InBlock.gif if ( l2 == 0 )
ExpandedSubBlockStart.gif ContractedSubBlock.gif  dot.gif{
InBlock.gif  if ( re[re.Length-1] != '零' && l1 != 0 )
InBlock.gif   re += "零";
ExpandedSubBlockEnd.gif }
InBlock.gif else
InBlock.gif  re += _NumChinese[l2] + "拾"; 
InBlock.gif
InBlock.gif if ( l1 != 0 ) re += _NumChinese[l1]; 
InBlock.gif
InBlock.gif return re;
ExpandedBlockEnd.gif}
None.gif
None.gif

      直接调用GetNumCHN( decimal number ) 方法,填写入处理的数据金额,得到的就是大写的金额了。

      思想:把整个数字,分为8位一段,以“亿”阁开,8位以内,分成4位阁开,以万连接,最后剩下的就是四位,四位的万以内的数据了,把这些数据最后分别连接起来,再加上小数部分的处理,得到大写的结果了。

转载于:https://www.cnblogs.com/wjbs7188/archive/2007/02/13/649472.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值