将人民币的数字表示转化成大写表示(C#版)

using System;

namespace Test.Com
{
 /// <summary>
 /// 功能:字符串处理函数集
 /// </summary>
 public class DealString
 {
  #region 私有成员
  /// <summary>
  /// 输入字符串
  /// </summary>
  private string inputString=null;
  /// <summary>
  /// 输出字符串
  /// </summary>
  private string outString=null;
  /// <summary>
  /// 提示信息
  /// </summary>
  private string noteMessage=null;
  #endregion

  #region 公共属性
  /// <summary>
  /// 输入字符串
  /// </summary>
  public string InputString
  {
   get{return inputString;}
   set{inputString=value;}
  }
  /// <summary>
  /// 输出字符串
  /// </summary>
  public string OutString
  {
   get{return outString;}
   set{outString=value;}
  }
  /// <summary>
  /// 提示信息
  /// </summary>
  public string NoteMessage
  {
   get{return noteMessage;}
   set{noteMessage=value;}
  }
  #endregion
 
  #region 构造函数
  public DealString()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
  }
  #endregion

  #region 公共方法
  public void ConvertToChineseNum()
  {
   string numList="零壹贰叁肆伍陆柒捌玖";
   string rmbList = "分角元拾佰仟万拾佰仟亿拾佰仟万";
   double number=0;
   string tempOutString=null;

   try
   {
    number=double.Parse(this.inputString);
   }
   catch
   {
    this.noteMessage="传入参数非数字!";
    return;
   }
  
   if(number>9999999999999.99)
    this.noteMessage="超出范围的人民币值";

   //将小数转化为整数字符串
   string tempNumberString=Convert.ToInt64(number*100).ToString();
   int tempNmberLength=tempNumberString.Length;
   int i=0;
   while(i<tempNmberLength)
   {
    int oneNumber=Int32.Parse(tempNumberString.Substring(i,1));
    string oneNumberChar=numList.Substring(oneNumber,1);
    string oneNumberUnit=rmbList.Substring(tempNmberLength-i-1,1);
    if(oneNumberChar!="零")
     tempOutString+=oneNumberChar+oneNumberUnit;
    else
    {
     if(oneNumberUnit=="亿"||oneNumberUnit=="万"||oneNumberUnit=="元"||oneNumberUnit=="零")
     {
      while (tempOutString.EndsWith("零"))
      {
       tempOutString=tempOutString.Substring(0,tempOutString.Length-1);
      }

     }
     if(oneNumberUnit=="亿"||(oneNumberUnit=="万"&&!tempOutString.EndsWith("亿"))||oneNumberUnit=="元")
     {
      tempOutString+=oneNumberUnit;
     }
     else
     {
      bool tempEnd=tempOutString.EndsWith("亿");
      bool zeroEnd=tempOutString.EndsWith("零");
      if(tempOutString.Length>1)
      {
       bool zeroStart=tempOutString.Substring(tempOutString.Length-2,2).StartsWith("零");
       if(!zeroEnd&&(zeroStart||!tempEnd))
        tempOutString+=oneNumberChar;
      }
      else
      {
       if(!zeroEnd&&!tempEnd)
        tempOutString+=oneNumberChar;
      }
     }
    }
    i+=1;
   }

   while (tempOutString.EndsWith("零"))
   {
    tempOutString=tempOutString.Substring(0,tempOutString.Length-1);
   }

   while(tempOutString.EndsWith("元"))
   {
    tempOutString=tempOutString+"整";
   }

   this.outString=tempOutString;

  
  }
  #endregion
 }
}

转载于:https://www.cnblogs.com/hzuIT/articles/682812.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/408001.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C#图片切割

图片切割就是把一幅大图片按用户要求切割成多幅小图片。dotnet环境下系统提供了GDI类库&#xff0c;为图像操作处理提供了方便的接口。 下面是图像切割小程序&#xff1a; public class ImageManager { /// <summary> /// 图像切割 /// </s…

条件变量 ---C++17 多线程

条件变量 —C17 多线程 C标准库提供了条件变量的两种实现&#xff1a;std::condition_variable 和std::condition_variable_any。它们都在标准库的头文件<condition_variable>内声明。两者都需配合互斥&#xff0c;方能提供妥当的同步操作。std::condition_variable仅限…

关于在asp.net中textbox文本输入框中的汉语标点符号显示位置的问题

在asp.net中的服务器控件textbox中输入中文标点符号&#xff0c;位置处于输入框中间&#xff0c;而不是靠在左下角&#xff0c;解决办法&#xff1a;把字体样式设置为其它&#xff0c;比如&#xff1a;微软雅黑。这个问题&#xff0c;仅在宋体的时候出现过。 转载于:https://ww…

考验

如果不做网站&#xff0c;可以做着不错的工作&#xff0c;过着安逸的生活&#xff0c;可是&#xff0c;我不想年老的时候后悔&#xff1a;这一生竟然没有为自己的理想拼搏过!仅这一个理由&#xff0c;足以让我坚强地面对任何考验!博客园的发展需要付出更多努力&#xff0c;开始…

汇编常用命令、指令一览

MOV&#xff08;MOVe&#xff09; 传送指令P28 PUSH 入栈指令P32 POP 出栈指令P33 XCHG&#xff08;eXCHanG&#xff09; 交换指令P34 XLAT&#xff08;TRANSLATE&#xff09; 换码指令P34 LEA &#xff08;Load Effective Address&#xff09; 有效地址送…

std::future ---C++17 多线程

std::future —C17 多线程 std::future C标准程序库使用future来模拟这类一次性事件&#xff1a;若线程需等待某个特定的一次性事件发生&#xff0c;则会以恰当的方式取得一个future&#xff0c;它代表目标事件&#xff1b;接着&#xff0c;该线程就能一边执行其他任务&#…

VNCserver在Fedora上配置过程

前言&#xff1a;一直想写一下vncserver在redhat下详细配置过程&#xff0c;以帮助一些向我有同样需求却有懒得去读man page的朋友&#xff0c;后来在www.fedoranews.org上发现已经有人写了一个教程&#xff0c;并且还不错。干脆翻译算了。大家可以直接去阅原文&#xff0c;我这…

学好英语的42个经典要诀(完整版)

第一要诀&#xff1a;收听英语气象报告 有些教学录音带为配合初学者的学习&#xff0c;故意放慢语速&#xff0c;这对英语听力的训练是不够的。如果听语速正常的英语&#xff0c;初学者又会感到力不从心。英语气象报告的速度虽快&#xff0c;但词汇简单固定&#xff0c;内容单纯…

std::packaged_task() ---C++17 并发编程

std::packaged_task() —C17 并发编程 std::packaged_task<>连结了future对象与函数&#xff08;或可调用对象&#xff09;。 std::packaged_task<>对象在执行任务时&#xff0c;会调用关联的函数&#xff08;或可调用对象&#xff09;&#xff0c;把返回值保存为…

js分页--存储数据并进行分页

//分页方法var page function(){this.v {o:null,//ul父级层home:null,previous:null,next:null,last:null, list:[],pageSize:10,pageIndex:0,pageCount:0,rowCount:0};this.init function(){var _this this;_this.v.o.find("li").each(function(i,o){_this.v.…

c/c++面试试题(一)

1.求下面函数的返回值&#xff08;微软&#xff09;int func(x) { int countx 0; while(x) { countx ; x x&(x-1); } return countx; } 假定x 9999。 答案&#xff1a;8思路&#xff1a;将x转化为2进制&#xff0c;看含有的1…

react(78)--vs打开setting.json

1.ctrl shift p 2.输入setting 3.找到这一项

stdspan ---C++20

std::span —C20 std::span的定义 template<class T,std::size_t Extent std::dynamic_extent > class span;std::span是指向一组连续的对象的对象, 是一个视图view, 不是一个拥有者owner 一组连续的对象可以是 C 数组, 带着大小的指针, std::array, 或者 std::strin…

2. Get the codes from GIT

Clone the code from git. Click the “GitEx Clone”. Paste the url into the “Repository to clone”. You can get the route from git repository from it: https://msstash.companydomainname.com/ .Find the project which you want to download and then click the “…

按钮控件数组

Public Class ButtonArray Inherits System.Collections.CollectionBase Private ReadOnly HostForm As System.Windows.Forms.Form 创建类的构造函数。 Visual Basic Public Sub New(ByVal host As System.Windows.Forms.Form) HostForm host Me.Add…

c/c++面试试题(二)

21. New delete 与malloc free 的联系与区别?答案&#xff1a;都是在堆(heap)上进行动态的内存操作。用malloc函数需要指定内存分配的字节数并且不能初始化对象&#xff0c;new 会自动调用对象的构造函数。delete 会调用对象的destructor&#xff0c;而free 不会调用对象的des…

The Ranges Library (2) --- C++20

The Ranges Library (2) — C20 比较std与std::ranges算法 比较一下std::sort和std::ranges::sort std::sort template< class RandomIt > constexpr void sort( RandomIt first, RandomIt last );template< class ExecutionPolicy, class RandomIt > void sor…