using System;
using System.Collections.Generic;
using System.Text;
public class NumToCharactor
{
/// <summary>
/// 要转换的数字
/// </summary>
private int j;
/// <summary>
///
/// </summary>
private string[] Digitals = new string[] { "〇", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
private string[] Unit = new string[] { "", "十", "百", "千", "万", "十", "百", "千", "亿", "十", "百", "千", "万" };
public NumToCharactor()
{
this.j = 0;
}
public NumToCharactor(int m)
{
this.j = m;
}
/// <summary>
/// 数字转换成汉字主函数
/// </summary>
/// <returns>返回转换后的汉字</returns>
public string Convert(int num,bool btype)
{
char[] strNum = num.ToString().ToCharArray();
string chsNum = "";
if (btype == false) //转月 日
{
int high = strNum.Length - 1;
int plus = 0;
char zero = '0';
for (int i = high; i >= 0; i--)
{
if (plus == 4)
plus = 0;
if (zero == '0' && strNum[i] == '0')
strNum[i] = '-';
else
zero = strNum[i];
if (i < (i + plus) && i < (high - 3) && strNum[i] != '-' && strNum[i + plus] == '-')
strNum[i + plus] = '+';
if (plus == 1 && strNum[i] == '1' && i == 0)
strNum[i] = '+';
plus++;
}
if (strNum.Length == 1 && strNum[0] == '-')
strNum[0] = '0';
int unit = 0;
for (int j = high; j >= 0; j--)
{
if (strNum[j] != '-')
{
if (strNum[j] == '+')
chsNum = Unit[unit] + chsNum;
else if (strNum[j] == '0')
chsNum = Digitals[Int32.Parse(strNum[j].ToString())] + chsNum;
else
chsNum = Digitals[Int32.Parse(strNum[j].ToString())] + Unit[unit] + chsNum;
}
unit++;
}
}
else //转年份
{
int i = 0;
for (i = 0; i < strNum.Length; i++)
{
chsNum += Digitals[Int32.Parse(strNum[i].ToString())];
}
}
return chsNum;
}
}