^[\\w-]+@[\\w-]+\\.(com|net|org|edu|mil|tv|biz|info)$
将数字(1.00)格式的钱数表示形式转换成大写汉字(零 壹 贰 叁 肆 伍 陆柒捌玖)表示:
public class MyConvert
{
public static string ConvertToRMB(decimal num)
{
string text = "零壹贰叁肆伍陆柒捌玖";
string text2 = "万仟佰拾亿仟佰拾万仟佰拾元角分";
string text3 = "";
string str = "";
string str2 = "";
int num2 = 0;
num = Math.Round(Math.Abs(num), 2);
string text4 = ((long)(num * 100m)).ToString();
int length = text4.Length;
if (length > 15)
{
return "溢出";
}
text2 = text2.Substring(15 - length);
for (int i = 0; i < length; i++)
{
string text5 = text4.Substring(i, 1);
int startIndex = Convert.ToInt32(text5);
if (i != length - 3 && i != length - 7 && i != length - 11 && i != length - 15)
{
if (text5 == "0")
{
str = "";
str2 = "";
num2++;
}
else
{
if (text5 != "0" && num2 != 0)
{
str = "零" + text.Substring(startIndex, 1);
str2 = text2.Substring(i, 1);
num2 = 0;
}
else
{
str = text.Substring(startIndex, 1);
str2 = text2.Substring(i, 1);
num2 = 0;
}
}
}
else
{
if (text5 != "0" && num2 != 0)
{
str = "零" + text.Substring(startIndex, 1);
str2 = text2.Substring(i, 1);
num2 = 0;
}
else
{
if (text5 != "0" && num2 == 0)
{
str = text.Substring(startIndex, 1);
str2 = text2.Substring(i, 1);
num2 = 0;
}
else
{
if (text5 == "0" && num2 >= 3)
{
str = "";
str2 = "";
num2++;
}
else
{
if (length >= 11)
{
str = "";
num2++;
}
else
{
str = "";
str2 = text2.Substring(i, 1);
num2++;
}
}
}
}
}
if (i == length - 11 || i == length - 3)
{
str2 = text2.Substring(i, 1);
}
text3 = text3 + str + str2;
if (i == length - 1 && text5 == "0")
{
text3 += '整';
}
}
if (num == 0m)
{
text3 = "零元整";
}
return text3;
}
public static string ConvertToRMB(string numstr)//此处重写
{
string result;
try
{
decimal num = Convert.ToDecimal(numstr);
result=ConvertToRMB(num);
}
catch
{
result = "非数字形式!";
}
return result;
}
}
下面是调用的例子
class Program
{
static void Main(string[] args)
{
MyConvert convert=new Myconvert();
Console.WriteLine("The Value Is:{0}",convert.ConvertRMB("12.23"));
Console.WriteLine("The Value Is:{0}",convert.ConvertRMB(12.23m));
Console.ReadKey();
}
输出结果自己运行