function MoneyName(Value: Double): string;
const
SCnNumber = '零壹贰叁肆伍陆柒捌玖';
SCnPower = '拾佰仟';
var
V, V1: Double;
X: array[0..4] of Integer; //分别表示万亿位、亿位、万位、元位、分位
N, P, I, J: Integer; //内部使用
S: array[0..4] of string; //目标串
B: array[0..4] of Boolean; //是否零前缀
BK, BL: Boolean;
begin
V := Int(Value);
X[4] := Trunc((Value - V) * 100 + 0.5); //分位
X[0] := 0; //万亿位
X[1] := 0; //亿位
X[2] := 0; //万位
X[3] := 0; //元位
I := 3;
while (V > 0) and (I >= 0) do
begin
V1 := Int(V / 10000) * 10000;
X[I] := Trunc(V - V1);
Dec(I);
V := V1 / 10000;
end;
BL := True; //检查是否全为零
for I := 0 to 4 do
if X[I] <> 0 then
begin
BL := False;
Break;
end;
if BL then
Result := '零元整'
else
begin
//先计算整数部分每节的串
for I := 0 to 3 do
begin
S[I] := '';
if X[I] > 0 then
begin
B[I] := False;
P := 1000;
BK := False; //前位为零
BL := False; //未记录过
for J := 0 to 3 do
begin
N := X[I] div P; //当前位
X[I] := X[I] - N * P; //剩余位
P := P div 10; //幂
if N = 0 then //当前位为零
begin
if J = 0 then
B[I] := True //如果是最高位
else
if BL then //如果未记录过
BK := True;
end
else
begin
if BK then
S[I] := S[I] + '零';
BL := True;
S[I] := S[I] + Copy(SCnNumber, N * 2 + 1, 2);
if J < 3 then
S[I] := S[I] + Copy(SCnPower, (3 - J) * 2 - 1, 2);
BK := False;
end;
end;
end;
end;
//小数部分
BL := False;
if X[4] mod 10 > 0 then
S[4] := Copy(SCnNumber, (X[4] mod 10) * 2 + 1, 2) + '分'
else
begin
BL := True;
S[4] := '';
end;
X[4] := X[4] div 10;
if X[4] > 0 then
begin
S[4] := Copy(SCnNumber, (X[4] mod 10) * 2 + 1, 2) + '角' + S[4];
B[4] := False;
end
else
B[4] := not BL;
//合并串
Result := '';
BL := False;
for I := 0 to 3 do
if Length(S[I]) > 0 then
begin
if BL then
if B[I] then
Result := Result + '零';
Result := Result + S[I];
case I of
0, 2: Result := Result + '万';
1: Result := Result + '亿';
3: Result := Result + '元';
end;
BL := True;
end
else
if BL then
case I of
1: Result := Result + '亿';
3: Result := Result + '元';
end;
if Length(S[4]) = 0 then
Result := Result + '整'
else
begin
if B[4] then
if BL then
Result := Result + '零';
Result := Result + S[4];
end;
end;
end;
delphi 金额转为中文
于 2010-07-05 13:30:00 首次发布