用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - c#代码库

阿拉伯数字金额转换为中文大写金额

2014-05-24 作者: 苏起举报

[c#]代码库

/// <summary>

    /// 将整数转为大写的中文数字

    /// </summary>

    /// <param name="ni_intInput"></param>

    /// <returns></returns>

    public static string ToCNUpperCase(int ni_intInput)

    {

      string tstrRet = "";

      int tintInput;

      int tintRemainder, tintDigitPosIndex = 0;

      int tintLoopX = 0;

       string[] tastrNumCNChar = new string[] { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };

      string[] tastrDigitPosCNChar = new string[] { "", "十", "佰", "仟", "万", "亿" };

      tintInput = ni_intInput;

       tintLoopX = 0;

      while (tintInput / 10 > 0 || tintInput > 0)

      {

        tintRemainder = (tintInput % 10);

         if (tintLoopX == 5)//十万

          tintDigitPosIndex = 1;

        else if (tintLoopX == 8)//亿

          tintDigitPosIndex = 5;

        else if (tintLoopX == 9)//十亿

          tintDigitPosIndex = 1;

        //end if

        if (tintRemainder > 0)

          tstrRet

            = tastrNumCNChar[tintRemainder] + tastrDigitPosCNChar[tintDigitPosIndex] + tstrRet;

        else

          tstrRet

            = tastrNumCNChar[tintRemainder] + tstrRet; ;

        //end if

         tintDigitPosIndex += 1;

         tintLoopX += 1;

        tintInput /= 10;

      }//end while

 

      tstrRet = System.Text.RegularExpressions.Regex.Replace(tstrRet, "零零*零*", "零");

      return tstrRet;

    }//end 
/// <summary>

    /// 将整数转为小写的中文数字

    /// </summary>

    /// <param name="ni_intInput"></param>

    /// <returns></returns>

    public static string ToCNLowerCase(this int ni_intInput)

    {

      string tstrRet = "";

      int tintInput;

      int tintRemainder, tintDigitPosIndex = 0;

      int tintLoopX = 0;

 

      string[] tastrNumCNChar = new string[] { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };

      string[] tastrDigitPosCNChar = new string[] { "", "十", "百", "千", "万", "亿" };

 

      tintInput = ni_intInput;

 

      tintLoopX = 0;

      while (tintInput / 10 > 0 || tintInput > 0)

      {

        tintRemainder = (tintInput % 10);

 

        if (tintLoopX == 5)//十万

          tintDigitPosIndex = 1;

        else if (tintLoopX == 8)//亿

          tintDigitPosIndex = 5;

        else if (tintLoopX == 9)//十亿

          tintDigitPosIndex = 1;

        //end if

 

        if (tintRemainder > 0)

          tstrRet

            = tastrNumCNChar[tintRemainder] + tastrDigitPosCNChar[tintDigitPosIndex] + tstrRet;

        else

          tstrRet

            = tastrNumCNChar[tintRemainder] + tstrRet; ;

        //end if

 

        tintDigitPosIndex += 1;

 

        tintLoopX += 1;

        tintInput /= 10;

      }//end while

       tstrRet = System.Text.RegularExpressions.Regex.Replace(tstrRet, "零零*零*", "零");

      return tstrRet;

    }//end


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...