首页 > 代码库 > 大写人民币xe2

大写人民币xe2

---恢复内容开始---

function Rmb2Dx(f: string): string;//支持宽字符
var
Fs, dx, d2, zs, xs, h, jg: string;
i, ws, {l,} w, j, lx: integer;
begin
f := Trim(f);
if copy(f, 1, 1) = ‘-‘ then
begin
Delete(f, 1, 1);
fs := ‘负‘;
end
else
fs := ‘‘;
dx := ‘零壹贰叁肆伍陆柒捌玖‘;
d2 := ‘拾佰仟万亿‘;
i := AnsiPos(‘.‘, f); //小数点位置
if i = 0 then
zs := f //整数
else
begin
zs := copy(f, 1, i - 1); //整数部分
xs := copy(f, i + 1, 200);
end;
ws := 0; //l := 0;
for i := Length(zs) downto 1 do
begin
ws := ws + 1;
h := ‘‘;
w := strtoint(copy(zs, i, 1));
if (w = 0) and (i = 1) then
jg := ‘零‘;
if w > 0 then
case ws of
2..5: h := copy(d2, ws - 1, 1);
6..8:
begin
h := copy(d2, ws - 5, 1);
if AnsiPos(‘万‘, jg) = 0 then
h := h + ‘万‘;
end;
10..13: h := copy(d2, ws - 9, 1);
end;
jg := copy(dx, w+1, 1) + h + jg;
if ws = 9 then
jg := copy(jg, 1, 1) + ‘亿‘ + copy(jg, 3, 200);
end;
j := AnsiPos(‘零零‘, jg);
while j > 0 do
begin
jg := copy(jg, 1, j - 1) + copy(jg, j + 1, 200);
j := AnsiPos(‘零零‘, jg);
end;
if (Length(jg) > 1) and (copy(jg, length(jg) - 1, 1) = ‘零‘) then
jg := copy(jg, 1, Length(jg) - 1);
j := AnsiPos(‘零亿‘, jg);
if j > 0 then
jg := copy(jg, 1, j - 1) + copy(jg, j + 1, 200);
//转换小数部分
lx := Length(xs);
if lx > 0 then
begin
jg := jg + ‘元‘;
for i := 1 to lx do
begin
if i = 1 then
begin
jg := jg + copy(dx, strtoint(copy(xs, i, 1)) + 1, 1);
jg := jg + ‘角‘;
end;
if i = 2 then
begin
jg := jg + copy(dx, strtoint(copy(xs, i, 1)) + 1, 1);
jg := jg + ‘分‘;
end;
end;
j := AnsiPos(‘零角零分‘, jg);
if j > 0 then
jg := copy(jg, 1, j - 1) + copy(jg, j + 4, 200) + ‘整‘;
j := AnsiPos(‘零角‘, jg);
i := AnsiPos(‘零分‘, jg);
if (j > 0) and (i > 0) then
jg := copy(jg, 1, j - 1) + copy(jg, j + 2, 200)
else
begin
if (j > 0) and (i = 0) then
jg := copy(jg, 1, j + 1) + copy(jg, j + 2, 200);
if i > 0 then
jg := copy(jg, 1, i - 1);
end;
end
else
jg := jg + ‘元整‘;
result := fs + jg;
end;

---恢复内容结束---

大写人民币xe2