数字换成大写中文
自己写的,不是很完美
有什么问题可别找我:))
const DX: array[0..9] of string[2] = ('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');
DW: array[1..3] of string[2] = ('仟', '佰', '拾');
D: array[1..3] of string[3] = ('圆 ', '万 ', '亿 ');
function Convert(s: string): string;
function AZ(s: string): string;
var i: integer;
begin
for i := 1 to 4 - length(s) do
s := '0' + s;
result := s;
end;
function GZN(s: string): integer;
var i: integer;
begin
result := 0;
for i := 1 to 4 do
begin
if S <> '0' then
break;
result := result + 1;
end;
end;
function Cvt(s: string): string;
var flag: boolean;
i: integer;
begin
result := '';
flag := false;
for i := 4 downto 1 do
begin
if flag = false then
if s <> '0' then
flag := true;
if s <> '0' then
if i = 4 then
result := DX[strtoint(s)] + result
else
result := DX[strtoint(s)] + DW + result
else
if (flag) and (i > GZN(s)) then
begin
flag := false;
result := DX[0] + result;
end;
end;
end;
var p: integer;
s1, s2, ss: string;
i, n, l: integer;
f: double;
begin
for i := 1 to length(s) do
if not (s in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.']) then
begin
showmessage('含有非法字符!');
exit
end;
result := '';
p := pos('.', s);
if length(s) - p = 1 then
s := s + '0';
if p = 0 then
s1 := s
else
begin
s1 := copy(s, 1, p - 1);
s2 := copy(s, p + 1, 2);
end;
l := length(s1);
if l > 12 then
begin
showmessage('位数太多!');
exit;
end;
if (l mod 4) = 0 then
n := l div 4
else
n := l div 4 + 1;
for i := 1 to n do
begin
if i < n then
begin
ss := copy(s1, l - 3, 4);
delete(s1, l - 3, 4);
l := length(s1);
end
else
begin
if length(s1) < 4 then
s1 := AZ(s1);
ss := s1;
end;
if strtoint(ss) <> 0 then
result := cvt(ss) + D + result
else if i = 1 then
result := '圆';
end;
if p > 0 then
begin
if s2[1] <> '0' then
result := result + DX[strtoint(s2[1])] + '角'
else
result := result + '零';
if s2[2] <> '0' then
result := result + DX[strtoint(s2[2])] + '分';
end;
end;