nbsp; }
int i;
if ((i=ret.IndexOf("零万"))!=-1)
ret = ret.Remove(i+1,1);
while ((i=ret.IndexOf("零零"))!=-1)
ret = ret.Remove(i,1);
if (ret[ret.Length-1]==''零'' && ret.Length>1)
ret = ret.Remove(ret.Length-1,1);
return ret;
}
private string ToDecimal(string x)
{
string ret="";
for (int i=0;i<x.Length;i++)
ret += ToNum(x[i]);
return ret;
}
public string NumToChn(string x)
{
if (x.Length==0)
return "";
string ret="";
if (x[0]==''-'')
{
ret="负";
x=x.Remove(0,1);
}
if (x[0].ToString()==".")
x="0"+x;
if (x[x.Length-1].ToString()==".")
x=x.Remove(x.Length-1,1);
if (x.IndexOf(".")>-1)
ret += ToInt(x.Substring(0,x.IndexOf(".")))+"点"+ToDecimal(x.Substring(x.IndexOf(".")+1));
else
ret += ToInt(x);
return ret;
}
}
}
测试工程
using System;
namespace ConsoleApp
{
class MainClass
{
static void Main(string args)
{
/*
System.Console.WriteLine("Hello, The World!");
System.Console.WriteLine("My Love!");
ClassTest ct = new ClassTest();
System.Console.WriteLine(ct.Get_Str());
*/
/*
// 重载运算符
MyVector v1 = new MyVector(5, 12);
MyVector v2 = new MyVector(4, 3);
MyVector v3 = new MyVector();
v3 = v1 + v2;
System.Console.WriteLine("{0}测试一下", v3.Length);
*/
// 转换成大写数字
NumFormat nf = new NumFormat();
string x;
while (true)
{
Console.Write("X=");
x = Console.ReadLine();
if (x == "") break;
Console.WriteLine("{0}={1}", x, nf.NumToChn(x));
}
}
}
}