sadier

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  50 随笔 :: 274 文章 :: 276 评论 :: 61万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

  private string Num2TraWord(string MoneyNoStr)
  {
   string sourNostr = MoneyNoStr;
   string[] strary = sourNostr.Split('.');
  
   if (strary[0].Length > 0)
    strary[0] = strary[0].Insert(strary[0].Length,"元");
   if (strary[0].Length > 2)
    strary[0] = strary[0].Insert(strary[0].Length-2,"拾");
   if (strary[0].Length > 4)
    strary[0] = strary[0].Insert(strary[0].Length-4,"佰");
   if (strary[0].Length > 6)   
    strary[0] = strary[0].Insert(strary[0].Length-6,"仟");
   if (strary[0].Length > 8)
    strary[0] = strary[0].Insert(strary[0].Length-8,"万");
   if (strary[0].Length > 10)
    strary[0] = strary[0].Insert(strary[0].Length-10,"拾");
   if (strary[0].Length > 12)
    strary[0] = strary[0].Insert(strary[0].Length-12,"佰");
   if (strary[0].Length > 14)   
    strary[0] = strary[0].Insert(strary[0].Length-14,"仟");

   try
   {
    if (strary[1].Length > 0)
     strary[1] = strary[1].Insert(1,"角");
    if (strary[1].Length > 2)
     strary[1] = strary[1].Insert(3,"分");

    sourNostr = strary[0] + strary[1];
   }
   catch
   {
    sourNostr = strary[0];
   }

   sourNostr = sourNostr.Replace("0","零");
   sourNostr = sourNostr.Replace("1","壹");
   sourNostr = sourNostr.Replace("2","贰");
   sourNostr = sourNostr.Replace("3","叁");
   sourNostr = sourNostr.Replace("4","肆");
   sourNostr = sourNostr.Replace("5","伍");
   sourNostr = sourNostr.Replace("6","陆");
   sourNostr = sourNostr.Replace("7","柒");
   sourNostr = sourNostr.Replace("8","捌");
   sourNostr = sourNostr.Replace("9","玖");
   sourNostr = sourNostr.Replace("-","负");

   return sourNostr;
  }


二、
  private string Num2TaiWangWord(string MoneyNoStr)
  {
   string sourNostr = (Decimal.Parse(MoneyNoStr) * 100).ToString("0#");

   string[] InsertChar = {"分","角","元","拾","佰","仟","万","拾","佰","仟","亿"};
   int InsertPointer;
   int IntIndex = 0;

   for (InsertPointer = sourNostr.Length ; InsertPointer > 0 ; InsertPointer --)
   {
    if (((IntIndex % 4) == 2) || (sourNostr.Substring(InsertPointer - 1,1) != "0"))
     sourNostr = sourNostr.Insert(InsertPointer,InsertChar[IntIndex]);
    IntIndex ++;
    if (IntIndex > 10)
     IntIndex -= 8;
   }

   sourNostr = sourNostr.Replace("元00","元整");
   sourNostr = sourNostr.Replace("00","0");
   sourNostr = sourNostr.Replace("00","0");
   sourNostr = sourNostr.Replace("0元","元");
   sourNostr = sourNostr.Replace("0万","万");
   sourNostr = sourNostr.Replace("0亿","亿");
   sourNostr = sourNostr.Replace("亿万","亿");

   sourNostr = sourNostr.Replace("0","零");
   sourNostr = sourNostr.Replace("1","壹");
   sourNostr = sourNostr.Replace("2","贰");
   sourNostr = sourNostr.Replace("3","叁");
   sourNostr = sourNostr.Replace("4","肆");
   sourNostr = sourNostr.Replace("5","伍");
   sourNostr = sourNostr.Replace("6","陆");
   sourNostr = sourNostr.Replace("7","柒");
   sourNostr = sourNostr.Replace("8","捌");
   sourNostr = sourNostr.Replace("9","玖");
   sourNostr = sourNostr.Replace("-","(负数)");

   return sourNostr;
  }

posted on   毛小华  阅读(2404)  评论(5编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示