获取中文大写金额,连续为0时只转换一个
function GetChineseMoney(const AMoney: Double): string;
const
Digits: array [0 .. 9] of string = ('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒',
'捌', '玖');
Tens: array [0 .. 4] of string = ('拾', '佰', '仟', '万', '亿');
var
S0: TBytes;
s, s1: string;
Pos, J: Integer;
I: LongInt;
ZeroYen, ZeroFen, IsYi: Boolean;
begin
IsYi := false;
S0 := BytesOf(Format('%f', [AMoney]));
ZeroYen := true;
ZeroFen := true;
Pos := Length(S0) - 1;
I := Ord(S0[Pos]) - $30;
if I > 0 then
begin
s1 := Digits[I] + '分';
ZeroFen := false;
end;
Pos := Pos - 1;
I := Ord(S0[Pos]) - $30;
if (s1 <> '') or (I > 0) then
if I <> 0 then
s1 := Digits[I] + '角' + s1
else if s1 <> '' then
s1 := Digits[I] + s1;
Pos := Pos - 2;
I := Ord(S0[Pos]) - $30;
if (s <> '') or (I > 0) then
begin
s := Digits[I] + '元';
ZeroYen := false;
end;
Pos := Pos - 1;
J := 0;
while Pos >= 0 do
begin
I := Ord(S0[Pos]) - $30;
if (s <> '') or (I > 0) then
begin
if I <> 0 then
s := Digits[I] + Tens[J] + s
else if (Copy(s, 1, 1) <> '零') and (Copy(s, 1, 1) <> '万') and
(Copy(s, 1, 1) <> '亿') then
begin
s := Digits[I] + s;
if ((J = 3) or (J = 4)) and (Pos > 1) then
s := Tens[J] + s;
end
else if ((J = 3) or (J = 4)) and (Pos > 1) then
s := Tens[J] + s;
end;
Pos := Pos - 1;
J := J + 1;
if (not IsYi) and (J = 4) or (J = 5) then
begin
IsYi := true;
J := 0;
end
else if IsYi and (J = 3) then
J := 4;
end;
// -------------------
if s = '' then
begin
if s1 = '' then
s := '零元'
else
s := s1;
end
else
begin
if ZeroYen then
s := s + '元';
s := s + s1;
end;
if ZeroFen then
s := s + '整';
s := StringReplace(s, '亿万', '亿', [rfReplaceAll]);
s := StringReplace(s, '零万', '零', [rfReplaceAll]);
s := StringReplace(s, '零零', '零', [rfReplaceAll]);
Result := s;
end;
无
《学习大师原创文档,请勿转载,侵权必究》