C#中文数字表达式

string NumberCn(double ANumber)
{
    const string cPointCn = "点十百千万十百千亿十百千";
    const string cNumberCn = "零一二三四五六七八九";
    string S = ANumber.ToString();
    if (S == "0") return "" + cPointCn[0];
    if (!S.Contains(".")) S += ".";
    int P = S.IndexOf(".");
    string Result = "";
   
    for (int i = 0; i < S.Length; i++)
    {
        if (P == i)
        {
            Result = Result.Replace("零十零", "");
            Result = Result.Replace("零百零", "");
            Result = Result.Replace("零千零", "");
            Result = Result.Replace("零十", "");
            Result = Result.Replace("零百", "");
            Result = Result.Replace("零千", "");
            Result = Result.Replace("零万", "");
            Result = Result.Replace("零亿", "亿");
            Result = Result.Replace("亿万", "亿");
            Result = Result.Replace("零点", "");
        }
        else
        {
            if (P > i)
                Result += "" + cNumberCn[S[i] - '0'] + cPointCn[P - i - 1];
            else Result += "" + cNumberCn[S[i] - '0'];
        }
    }
    if (Result.Substring(Result.Length - 1, 1) == "" + cPointCn[0])
        Result = Result.Remove(Result.Length - 1); // 一点->
   
    if (Result[0] == cPointCn[0])
        Result = cNumberCn[0] + Result; // 点三-> 零点三
 
    if ((Result.Length > 1) && (Result[1] == cPointCn[1]) &&
       (Result[0] == cNumberCn[1]))
       Result = Result.Remove(0, 1); // 一十三-> 十三
    return Result;
}
 
string MoneyCn(double ANumber)
{
    if (ANumber == 0) return "";
    string Result = NumberCn(Math.Truncate(ANumber * 100) / 100);
    Result = Result.Replace("", "");
    Result = Result.Replace("", "");
    Result = Result.Replace("", "");
    Result = Result.Replace("", "");
    Result = Result.Replace("", "");
    Result = Result.Replace("", "");
    Result = Result.Replace("", "");
    Result = Result.Replace("", "");
    Result = Result.Replace("", "");
    Result = Result.Replace("", "");
    Result = Result.Replace("", "");
    Result = Result.Replace("", "");
    Result = Result.Replace("", "");
    if (Result.Contains(""))
    {
        int P = Result.IndexOf("");
        Result = Result.Insert(P + 3, "");
        Result = Result.Insert(P + 2, "");
        Result = Result.Replace("", "");
        Result = Result.Replace("角分", "");
        Result = Result.Replace("零分", "");
        Result = Result.Replace("零角", "");
        Result = Result.Replace("分角", "");
        if (Result.Substring(0, 2) == "零圆")
            Result = Result.Replace("零圆", "");
    } else Result += "圆整";
    Result = "人民币" + Result;
    return Result;
}
 
 
 
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值