using NSNumTranslateFactory;
namespace NSNumToChs
{
public class NumToChs : NumTranslateFactory
{
private string StIntUnit = "萬千佰拾億千佰拾萬千佰拾元角分厘毫";
private string StCht = "零壹貳參肆伍陸柒捌玫";
public override string GetTransResult(double Num, int DigCount)
{
int NumLen;
string StIntResult = "", StActuUnit = "";
Num = System.Math.Round(Num, DigCount);
Num = Num * System.Math.Pow(10, DigCount);
string StNum = Num.ToString();
NumLen = Num.ToString().Length;
StActuUnit = StIntUnit.Substring(12+DigCount - NumLen + 1, NumLen);
for (int i = 0; i < NumLen; i++)//connect the stnumtemp and stint
{
StIntResult = StIntResult + StCht[StNum[i] - 48] + StActuUnit[i];
}
StIntResult = StIntResult.Replace("零拾", "零");
StIntResult = StIntResult.Replace("零佰", "零");
StIntResult = StIntResult.Replace("零千", "零");
StIntResult = StIntResult.Replace("零角", "零");
StIntResult = StIntResult.Replace("零分", "零");
StIntResult = StIntResult.Replace("零厘", "零");
StIntResult = StIntResult.Replace("零毫", "零");
StIntResult = StIntResult.Replace("零零零", "零");
StIntResult = StIntResult.Replace("零零", "零");
StIntResult = StIntResult.Replace("零萬", "萬");
StIntResult = StIntResult.Replace("零億", "億");
StIntResult = StIntResult.Replace("零元", "元");
if (StIntResult[StIntResult.Length-1]=='零')
{
StIntResult = StIntResult.Substring(0, StIntResult.Length - 1);
}
return StIntResult;
}
}
}