Y
Yang J.Q.
Unregistered / Unconfirmed
GUEST, unregistred user!
下面就是,若有需改进的地方或更好的方法,请指教。
function DaXie(XiaoXieJinE:do
uble): string;
var
DaXieCurr: String;
// 存放大写金额字符串
IntPart, FracPart: String;
// 存放整数与小数部分的字符串
IntLength, FracLength: Integer;
// 整数与小数部分各自的长度
PrevZero: Boolean;
// 前一位是否为0(连续的0只输出一个)
I, J: Integer;
begin
try
DaXieCurr := CurrToStr(Round(XiaoXieJinE*100.0)/100.0);
except
Application.MessageBox('金额过大,不能转换成货币大写格式!',
'警告:', MB_OK);
try
Result := '(巨额)' + FloatToStr(Round(XiaoXieJinE*100.0)/100.0)+ '(巨额)';
except
Result := '(金额超大!!!)';
end;
Exit;
end;
// if StrToFloat(DaXieCurr) = 0 then
// begin
// Result := '零元';
// Exit;
// end;
//分离整数部分(IntPart)和小数部分(FracPart),
//并分别求出它们的长度(IntLength,FracLength).
IntLength := Pos('.', DaXieCurr)-1;
if IntLength = -1 then
begin
//没找到'.',因此是整数.
IntPart := DaXieCurr;
IntLength := Length(DaXieCurr);
FracPart := '';
FracLength := 0;
end
else
begin
IntPart := Copy(DaXieCurr, 1, IntLength);
FracLength := Length(DaXieCurr) - IntLength - 1;
FracPart := Copy(DaXieCurr, IntLength+2, FracLength);
end;
DaXieCurr := '';
PrevZero := False;
// 处理整数部分
if (IntLength=0) or (StrToInt64(IntPart)=0) then
begin
if (FracLength=0) or (StrToFloat(FracPart)=0.0) then
begin
Result := '零元';
Exit;
end
end
else
begin
for I:=1 to IntLengthdo
begin
J := IntLength - I;
// 当前数字所处'位'编号
if IntPart='0' then
begin
if not PrevZero then
PrevZero := True;
end
else
begin
if PrevZero then
DaXieCurr := DaXieCurr + '0';
PrevZero := False;
case (J mod 4) of
3: DaXieCurr := DaXieCurr + IntPart + '仟';
2: DaXieCurr := DaXieCurr + IntPart + '佰';
1: DaXieCurr := DaXieCurr + IntPart + '拾';
0: DaXieCurr := DaXieCurr + IntPart;
end;
end;
if (J mod 4) = 0 then
// 升位处理:'万'与'亿'
begin
case (J div 4) mod 2 of
0:
if (J div 4)=0 then
DaXieCurr := DaXieCurr + '元'
else
DaXieCurr := DaXieCurr + '亿';
1: DaXieCurr := DaXieCurr + '万';
end;
end;
end;
end;
if (FracLength<>0) and (StrToFloat(FracPart)<>0.0) then
begin
if FracPart[1] <> '0' then
begin
DaXieCurr := DaXieCurr + FracPart[1] + '角';
if FracPart[2] <> '0' then
DaXieCurr := DaXieCurr + FracPart[2] + '分';
end
else
begin
if FracPart[2] <> '0' then
begin
if (IntLength<>0) and (StrToInt64(IntPart)<>0) then
DaXieCurr := DaXieCurr + '0';
DaXieCurr := DaXieCurr + FracPart[2] + '分';
end;
end;
end
else
DaXieCurr := DaXieCurr + '正';
DaXieCurr := StringReplace(DaXieCurr, '0', '零', [rfReplaceAll]);
DaXieCurr := StringReplace(DaXieCurr, '1', '壹', [rfReplaceAll]);
DaXieCurr := StringReplace(DaXieCurr, '2', '贰', [rfReplaceAll]);
DaXieCurr := StringReplace(DaXieCurr, '3', '叁', [rfReplaceAll]);
DaXieCurr := StringReplace(DaXieCurr, '4', '肆', [rfReplaceAll]);
DaXieCurr := StringReplace(DaXieCurr, '5', '伍', [rfReplaceAll]);
DaXieCurr := StringReplace(DaXieCurr, '6', '陆', [rfReplaceAll]);
DaXieCurr := StringReplace(DaXieCurr, '7', '柒', [rfReplaceAll]);
DaXieCurr := StringReplace(DaXieCurr, '8', '捌', [rfReplaceAll]);
DaXieCurr := StringReplace(DaXieCurr, '9', '玖', [rfReplaceAll]);
Result := DaXieCurr;
end;
function DaXie(XiaoXieJinE:do
uble): string;
var
DaXieCurr: String;
// 存放大写金额字符串
IntPart, FracPart: String;
// 存放整数与小数部分的字符串
IntLength, FracLength: Integer;
// 整数与小数部分各自的长度
PrevZero: Boolean;
// 前一位是否为0(连续的0只输出一个)
I, J: Integer;
begin
try
DaXieCurr := CurrToStr(Round(XiaoXieJinE*100.0)/100.0);
except
Application.MessageBox('金额过大,不能转换成货币大写格式!',
'警告:', MB_OK);
try
Result := '(巨额)' + FloatToStr(Round(XiaoXieJinE*100.0)/100.0)+ '(巨额)';
except
Result := '(金额超大!!!)';
end;
Exit;
end;
// if StrToFloat(DaXieCurr) = 0 then
// begin
// Result := '零元';
// Exit;
// end;
//分离整数部分(IntPart)和小数部分(FracPart),
//并分别求出它们的长度(IntLength,FracLength).
IntLength := Pos('.', DaXieCurr)-1;
if IntLength = -1 then
begin
//没找到'.',因此是整数.
IntPart := DaXieCurr;
IntLength := Length(DaXieCurr);
FracPart := '';
FracLength := 0;
end
else
begin
IntPart := Copy(DaXieCurr, 1, IntLength);
FracLength := Length(DaXieCurr) - IntLength - 1;
FracPart := Copy(DaXieCurr, IntLength+2, FracLength);
end;
DaXieCurr := '';
PrevZero := False;
// 处理整数部分
if (IntLength=0) or (StrToInt64(IntPart)=0) then
begin
if (FracLength=0) or (StrToFloat(FracPart)=0.0) then
begin
Result := '零元';
Exit;
end
end
else
begin
for I:=1 to IntLengthdo
begin
J := IntLength - I;
// 当前数字所处'位'编号
if IntPart='0' then
begin
if not PrevZero then
PrevZero := True;
end
else
begin
if PrevZero then
DaXieCurr := DaXieCurr + '0';
PrevZero := False;
case (J mod 4) of
3: DaXieCurr := DaXieCurr + IntPart + '仟';
2: DaXieCurr := DaXieCurr + IntPart + '佰';
1: DaXieCurr := DaXieCurr + IntPart + '拾';
0: DaXieCurr := DaXieCurr + IntPart;
end;
end;
if (J mod 4) = 0 then
// 升位处理:'万'与'亿'
begin
case (J div 4) mod 2 of
0:
if (J div 4)=0 then
DaXieCurr := DaXieCurr + '元'
else
DaXieCurr := DaXieCurr + '亿';
1: DaXieCurr := DaXieCurr + '万';
end;
end;
end;
end;
if (FracLength<>0) and (StrToFloat(FracPart)<>0.0) then
begin
if FracPart[1] <> '0' then
begin
DaXieCurr := DaXieCurr + FracPart[1] + '角';
if FracPart[2] <> '0' then
DaXieCurr := DaXieCurr + FracPart[2] + '分';
end
else
begin
if FracPart[2] <> '0' then
begin
if (IntLength<>0) and (StrToInt64(IntPart)<>0) then
DaXieCurr := DaXieCurr + '0';
DaXieCurr := DaXieCurr + FracPart[2] + '分';
end;
end;
end
else
DaXieCurr := DaXieCurr + '正';
DaXieCurr := StringReplace(DaXieCurr, '0', '零', [rfReplaceAll]);
DaXieCurr := StringReplace(DaXieCurr, '1', '壹', [rfReplaceAll]);
DaXieCurr := StringReplace(DaXieCurr, '2', '贰', [rfReplaceAll]);
DaXieCurr := StringReplace(DaXieCurr, '3', '叁', [rfReplaceAll]);
DaXieCurr := StringReplace(DaXieCurr, '4', '肆', [rfReplaceAll]);
DaXieCurr := StringReplace(DaXieCurr, '5', '伍', [rfReplaceAll]);
DaXieCurr := StringReplace(DaXieCurr, '6', '陆', [rfReplaceAll]);
DaXieCurr := StringReplace(DaXieCurr, '7', '柒', [rfReplaceAll]);
DaXieCurr := StringReplace(DaXieCurr, '8', '捌', [rfReplaceAll]);
DaXieCurr := StringReplace(DaXieCurr, '9', '玖', [rfReplaceAll]);
Result := DaXieCurr;
end;