using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RMBTest
{
class Program
{
public static string[] MyScale = { "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "兆", "拾", "佰", "仟" };
public static string[] MyScale2 = { "分", "角" };
public static string[] MyBase = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
static void Main(string[] args)
{
while (true)
{
Console.WriteLine("请输入你要转换的金额:");
string sMoney = Console.ReadLine();
string result = "";
try
{
double dm = double.Parse(sMoney);
string[] array = dm.ToString().Split('.');
int n = 0;
char[] cYuan;
char[] cJiao;
if (array.Length == 2)
{
if (array[1].Length > 2)
{
Console.WriteLine("你所输入的金额错误,无法转换,请重新输入!\n");
continue;
}
cYuan = array[0].ToString().ToCharArray();
n = cYuan.Length;
for (int i = 0; i < cYuan.Length; i++)
{
result += MyBase[Convert.ToInt32(cYuan[i].ToString())];
result += MyScale[Convert.ToInt32(n) - 1];
n--;
}
cJiao = array[1].ToString().ToCharArray();
n = cJiao.Length;
for (int i = 0; i < cJiao.Length; i++)
{
result += MyBase[Convert.ToInt32(cJiao[i].ToString())];
result += MyScale2[Convert.ToInt32(n) - 1];
n--;
}
}
else
{
cYuan = dm.ToString().ToCharArray();
n = cYuan.Length;
for (int i = 0; i < cYuan.Length; i++)
{
result += MyBase[Convert.ToInt32(cYuan[i].ToString())];
result += MyScale[Convert.ToInt32(n) - 1];
n--;
}
}
Console.WriteLine(result);
}
catch
{
Console.WriteLine("你所输入的金额错误,无法转换,请重新输入!\n");
continue;
}
}
}
}
}