怎么样将货币数字转换成中文大写?

怎么样将货币数字转换成中文大写?

这个函数与以前其他网友提供的结构大不相同, 是一个从高位到低位的算法, 更加符合语言习惯.


//------------------------------------------------------------------------
// 货币数字转换成中文大写的函数, 整数部分最多16位,也就是"千兆"
//------------------------------------------------------------------------
AnsiString __fastcall TFineInvoice::MoneyToChineseChar(Currency MoneyValue)
{
static char *ChinaNumberChar[10] = {"零","壹","贰","叁","肆"
,"伍","陆","柒","捌","玖"};
static char *ChinaUnitChar[4] = {"兆","亿","万","元"};
static char *ChinaBitChar[3] = {"仟","佰","拾"};

AnsiString expDecimal = "00";
AnsiString expInteger = MoneyValue;
AnsiString expChinese = "";

AnsiString expNumber, expMoney;
int intBit;

// 拆分整数与小数
if (expInteger.Pos("."))
{
expDecimal = expInteger.SubString(expInteger.Pos(".")+1,2) + "00";
expInteger.SetLength(expInteger.Pos(".")-1);
expDecimal.SetLength(2);
}

// 处理负数
if (expInteger.SubString(1,1) == "-")
{
expChinese += "(负数)";
expInteger.Delete(1,1);
}

// 处理整数部分
for (int i=16-expInteger.Length(); i<16; i++)
{
expNumber = "";
expMoney = "";


intBit = expInteger.SubString(1,1).ToIntDef(0);
if (intBit || (expMoney.Length() && i%4 < 3))
expNumber = ChinaNumberChar[intBit];

if (i%4 == 3)
expMoney = ChinaUnitChar[i/4];
else if (intBit)
expMoney = ChinaBitChar[i%4];

if (intBit == 0 && i%4 == 3
&& expChinese.SubString(expChinese.Length()-1,2) == "零")
expChinese.SetLength(expChinese.Length()-2);
expChinese += expNumber + expMoney;
expInteger.Delete(1,1);
}

// 处理小数部分
if (expDecimal.ToIntDef(0))
{
intBit = expDecimal.SubString(1,1).ToIntDef(0);
if (intBit)
{
expChinese += ChinaNumberChar[intBit];
expChinese += "角";
}

intBit = expDecimal.SubString(2,1).ToIntDef(0);
if (intBit)
{
if (expChinese.SubString(expChinese.Length()-1,2) == "元")
expChinese += "零";
expChinese += ChinaNumberChar[intBit];
expChinese += "分";
}
else expChinese += "整"; // 这个"整"有人说不必要!
}
else expChinese += "整";

return expChinese;
}
//------------------------------------------------------------------------
以下这段程序小的正在(Borland C++)使用中,没有问题。

AnsiString __fastcall TForm_Vip::DX(float Xx)//金额小写转大写
{
AnsiString ShuZi="零壹贰叁肆伍陆柒捌玖";
AnsiString DanWei="分 角 元 拾 百 千 万拾万百万千万 亿十亿百亿";
AnsiString XxStr=FormatFloat("0.00",Xx),DxStr="";

for(int i=XxStr.Length();i>=1;i--)
{
if(XxStr.SubString(i,1)!=".")
DxStr=ShuZi.SubString(StrToInt(XxStr.SubString(i,1))*2+1,2)
+Trim(DanWei.SubString((XxStr.Length()-i)*4,4))+DxStr;
}
return DxStr;
}