易做图数字转换大写
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LYWJMIS.AssistantClass
{
class ArabConventToCapital
{
/// <summary>
/// 要转换的数字
/// </summary>
private double j;
private string[] NumChineseCharacter = new string[] { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
public ArabConventToCapital(double m)
{
this.j = m;
}
/// <summary>
/// 判断输入的数字是否大于double类型
/// </summary>
private bool IsNumber
{
get
{
if (j > double.MaxValue || j <= 0)
return false;
else
return true;
}
}
/// <summary>
/// 数字转换成大写汉字主函数
/// </summary>
/// <returns>返回转换后的大写汉字</returns>
public string Convert()
{
string bb = "";
if (IsNumber)
{
string str = j.ToString();
string[] Num = str.Split('.');
if (Num.Length == 1)
{
bb = NumberString(Num[0]) + "元整";
bb = bb.Replace("零零", "零");
}
else
{
bb = NumberString(Num[0]) + "元";
bb += FloatString(Num[1]);
bb = bb.Replace("零零", "零");
}
}
else
{
throw new FormatException("你输入的数字格式不正确或不是数字!");
}
return bb;
}
/// <summary>
/// 小数位转换只支持两位的小数
/// </summary>
/// <param name="Num">转换的小数
/// <returns>小数转换成汉字</returns>
private string FloatString(string Num)
{
string cc = "";
if (Num.Length > 2)
{
throw new FormatException("小数位数过多.");
}
else
{
string bb = ConvertString(Num);
int len = bb.IndexOf("零");
if (len != 0)
{
bb = bb.Replace("零", "");
if (bb.Length == 1)
{
cc = bb.Substring(0, 1) + "角整";
}
else
{
cc = bb.Substring(0, 1) + "角";
cc += bb.Substring(1, 1) + "分";
}
}
else
cc = bb + "分";
}
return cc;
}
/// <summary>
/// 判断数字位数以进行拆分转换
/// </summary>
/// <param name="Num">要进行拆分的数字
/// <returns>转换成的汉字</returns>
private string NumberString(string Num)
{
string bb = "";
if (Num.Length <= 4)
{
bb = Convert4(Num);