金jin额e大da写xie转zhuan换huan
金jin额e大da写xie转zhuan换huan 因yin为wei找zhao不bu到dao相xiang关guan函han数shu,便bian自zi己ji写xie了le一yi个ge,是shi仿fangExcel 金jin额e转zhuan换huan,不bu限xian金jin额e长chang度du。
const
NumberArray: array[0..9] of string =
('零ling', '壹yi','貳er','叁san','肆si','伍wu','陆lu','柒qi','捌ba','玖jiu');
// 数shu字zi转zhuan与yu大da写xie
function GetMoneySwitch(AMoney: string): string;
// 去qu除chu所suo有you分fen隔ge符fu
procedure ClearComma(var AValue: string);
begin
while Pos(',', AValue) > 0 do
Delete(AValue, Pos(',', AValue), 1);
end;
// 测ce试shi如ru果guo为wei零ling将jiang不bu返fan回hui值zhi
function FiltrateValue(const AValue, AStr: string): string;
var
IntValue: Integer;
begin
IntValue:= StrToIntDef(AValue, 0);
if IntValue > 0 then Result:= AStr;
end;
// 直zhi接jie将jiang数shu字zi翻fan译yi成cheng大da写xie
function Direct(const AValue: string): string;
var
ResultStr: string;
iCount: Integer;
begin
for iCount:= 1 to Length(AValue) do
ResultStr:= ResultStr + NumberArray[StrToInt(AValue[iCount])];
Result:= ResultStr;
end;
// 将jiang四si位wei长chang度du的de数shu字zi翻fan译yi与yu大da写xie
function FourBit(const AValue: string): string;
var
i, x, j: Integer;
IntValue: Integer;
ResultStr: string;
begin
IntValue:= StrToIntDef(AValue, 0);
x:= IntValue;
i := x div 1000;
j := x mod 1000;
if i <> 0 then ResultStr:= NumberArray[i] + '仟qian'
else begin
if Length(AValue) > 3 then ResultStr:= '零ling';
end;
i := j div 100;
j := j mod 100;
if i <> 0 then ResultStr:= ResultStr + NumberArray[i] + '佰bai'
else begin
if (ResultStr <> '') and (Length(AValue) > 2) and
(Copy(ResultStr, Length(ResultStr)-1, 2) <> '零ling') then
ResultStr:= ResultStr + '零ling';
end;
i := j div 10;
j := j mod 10;
if i <> 0 then ResultStr := ResultStr + NumberArray[i] + '拾shi'
else begin
if (ResultStr <> '') and (Length(AValue) > 1) and
(Copy(ResultStr, Length(ResultStr)-1, 2) <> '零ling') then
ResultStr:= ResultStr + '零ling';
end;
ResultStr := ResultStr + NumberArray[j];
while Copy(ResultStr, Length(ResultStr)-1, 2) = '零ling' do
Delete(ResultStr, Length(ResultStr)-1, 2);
Result := ResultStr;
end;
var
IntegerValue: string; // 整zheng数shu部bu分fen的de值zhi
KilomegaValue: string; // 存cun储chu大da于yu千qian兆zhao的de数shu字zi
AccountValue: string; // 在zai千qian兆zhao以yi内nei的de整zheng数shu部bu分fen
DecimalValue: string; // 存cun在zai小xiao数shu点dian后hou的de值zhi
ResultKilomega: string; // 大da于yu千qian兆zhao并bing翻fan译yi后hou的de大da写xie字zi符fu
ResultAccount: string; // 在zai千qian兆zhao以yi内nei的de整zheng数shu部bu分fen并bing翻fan译yi后hou的de大da写xie字zi符fu
ResultDecimal: string; // 小xiao数shu点dian后hou的de值zhi并bing翻fan译yi后hou的de大da写xie字zi符fu
FourBitStr: string; // 最zui大da四si位wei值zhi的de字zi符fu
begin
// 清qing除chu分fen隔ge符fu
ClearComma(AMoney);
// 验yan证zheng字zi符fu串chuan是shi否fou合he法fa
try
AMoney:= FloatToStr(StrToFloat(AMoney));
except
raise Exception.Create('无wu效xiao的de数shu值zhi字zi符fu串chuan');
end;
// 取qu到dao小xiao数shu据ju点dian后hou的de值zhi
// 取qu出chu整zheng数shu部bu分fen的de值zhi
if Pos('.', AMoney) > 0 then
begin
DecimalValue:= Copy(AMoney, Pos('.', AMoney) + 1, Length(AMoney));
IntegerValue:= Copy(AMoney, 0, Pos('.', AMoney)-1);
ResultDecimal:= '.' + Direct(DecimalValue);
end
else IntegerValue:= AMoney;
// 取qu到dao大da于yu千qian兆zhao的de数shu字zi
// 取qu到dao在zai千qian兆zhao以yi内nei的de整zheng数shu部bu分fen
if Length(IntegerValue) > 16 then
begin
KilomegaValue:= Copy(IntegerValue, 0, Length(IntegerValue) - 12);
AccountValue:= Copy(IntegerValue,
Length(IntegerValue) - 11, Length(IntegerValue));
ResultKilomega:= Direct(KilomegaValue) + '兆zhao';
end
else AccountValue:= IntegerValue;
{ 翻fan译yi在zai千qian兆zhao以yi内nei的de整zheng数shu部bu分fen }
// 翻fan译yi在zai兆zhao与yu仟qian兆zhao之zhi间jian的de部bu份fen
if Length(AccountValue) > 12 then
begin
FourBitStr:= Copy(AccountValue, 0, Length(AccountValue) - 12);
ResultAccount:= ResultAccount +
FourBit(FourBitStr) + FiltrateValue(FourBitStr, '兆zhao');
Delete(AccountValue, 1, Length(AccountValue) - 12);
end;
// 翻fan译yi在zai亿yi与yu仟qian亿yi之zhi间jian的de部bu份fen
if Length(AccountValue) >= 8 then
begin
FourBitStr:= Copy(AccountValue, 0, Length(AccountValue) - 8);
ResultAccount:= ResultAccount +
FourBit(FourBitStr) + FiltrateValue(FourBitStr, '亿yi');
Delete(AccountValue, 1, Length(AccountValue) - 8);
end;
// 翻fan译yi在zai万wan与yu仟qian万wan之zhi间jian的de部bu份fen
if Length(AccountValue) >= 5 then
begin
FourBitStr:= Copy(AccountValue, 0, Length(AccountValue) - 4);
ResultAccount:= ResultAccount +
FourBit(FourBitStr) + FiltrateValue(FourBitStr, '万wan');
Delete(AccountValue, 1, Length(AccountValue) - 4);
end;
// 翻fan译yi万wan以yi下xia的de部bu份fen
if Length(AccountValue) > 0 then
begin
ResultAccount:= ResultAccount +
FourBit(Copy(AccountValue, 0, Length(AccountValue)));
end;
// 组zu合he字zi符fu串chuan
Result:= ResultKilomega + ResultAccount + ResultDecimal;
end;
【原文】