Delphi2010小写金额转大写金额的源代码
发表于2009年12月17日由admin
由于从Delphi2010开始支持大字符集,原来一个汉字占2个字节,现在Delphi2010中占一个字节,所以原函数在Delphi2010下已不能用了,现将原函数修改如下:
function ToBigRMB(Num: Currency): String;
const
BigNumber='零壹贰叁肆伍陆柒捌玖';
BigUnit='万仟佰拾亿仟佰拾万仟佰拾元';
{共可表示13位金额}
var
nLeft, nRigth, lTemp, rTemp, BigNumber1, BigUnit1, RMB,s: string;
I: Integer;
begin {取整数和小数部分}
RMB := FormatCurr('0.00', Num);
nLeft:=copy(RMB, 1, Pos('.', RMB) - 1);
nRigth:=copy(RMB, Pos('.', RMB) + 1, 2);
{转换整数部分}
if nLeft<>'0' then
for I:=1 to Length(nLeft) do
begin
BigNumber1:=copy(BigNumber, StrToInt(nLeft[I]) + 1, 1);
BigUnit1:=copy(BigUnit, (Length(BigUnit) - Length(nleft) + I - 1) + 1, 1);
s := copy(lTemp, Length(lTemp)-1, 1);
if (BigNumber1='零') and (s='零') then
lTemp:=copy(lTemp, 1, Length(lTemp) - 2);
if (BigNumber1='零') and ((BigUnit1='亿') or (BigUnit1='万') or (BigUnit1='元')) then
begin
BigNumber1:=BigUnit1;
if BigUnit1<>'元' then
BigUnit1:='零'
else
BigUnit1:='';
end;
if (BigNumber1='零') and (BigUnit1<>'亿') and (BigUnit1<>'万') and (BigUnit1<>'元') then
BigUnit1:='';
lTemp:=lTemp + BigNumber1 + BigUnit1;
end;
lTemp:=StringReplace(lTemp, '亿万', '亿', [rfReplaceAll]);
lTemp:=StringReplace(lTemp, '零零', '零', [rfReplaceAll]);
lTemp:=StringReplace(lTemp, '零元', '元', [rfReplaceAll]);
{转换小数部分}
if StrToInt(nRigth[1])<>0 then
rTemp:=copy(BigNumber, StrToInt(nRigth[1]) * 1 + 1, 1) + '角';
if StrToInt(nRigth[2])<>0 then
begin
if (nLeft<>'0') and (StrToInt(nRigth[1])=0) then
rTemp:='零';
rTemp:=rTemp + copy(BigNumber, StrToInt(nRigth[2]) * 1 + 1, 1) + '分';
RMB:=lTemp + rTemp;
end
else
RMB :=lTemp + rTemp + '整';
Result := RMB;
end;