谁能提供一个将数值型字符串转换为大写人民币表示形式的函数?(50分)

H

halen

Unregistered / Unconfirmed
GUEST, unregistred user!
谁能提供一个将数值型字符串转换为大写人民币表示形式的函数?
如14728.97转换为一万四千七百二十八元九角七分。
 
function Tform1.SmallTOBig(small:real):string;
var SmallMonth,BigMonth:string;
wei1,qianwei1:string[2];
wei,qianwei,dianweizhi,qian:integer;
begin
{------- 修改参数令值更精确 -------}
{小数点后的位置,需要的话也可以改动-2值}
qianwei:=-2;
{转换成货币形式,需要的话小数点后加多几个零}
Smallmonth:=formatfloat('0.00',small);
{---------------------------------}
dianweizhi :=pos('.',Smallmonth);{小数点的位置}
{循环小写货币的每一位,从小写的右边位置到左边}
for qian:=length(Smallmonth)do
wnto 1do
begin
{如果读到的不是小数点就继续}
if qian<>dianweizhi then
begin
{位置上的数转换成大写}
case strtoint(copy(Smallmonth,qian,1)) of
1:wei1:='壹';
2:wei1:='贰';
3:wei1:='叁';
4:wei1:='肆';
5:wei1:='伍';
6:wei1:='陆';
7:wei1:='柒';
8:wei1:='捌';
9:wei1:='玖';
0:wei1:='零';
end;
{判断大写位置,可以继续增大到real类型的最大值}
case qianwei of
-3:qianwei1:='厘';
-2:qianwei1:='分';
-1:qianwei1:='角';
0 :qianwei1:='元';
1 :qianwei1:='拾';
2 :qianwei1:='佰';
3 :qianwei1:='千';
4 :qianwei1:='万';
5 :qianwei1:='拾';
6 :qianwei1:='佰';
7 :qianwei1:='千';
8 :qianwei1:='亿';
9 :qianwei1:='十';
10:qianwei1:='佰';
11:qianwei1:='千';
end;
inc(qianwei);
BigMonth :=wei1+qianwei1+BigMonth;{组合成大写金额}
end;
end;
SmallTOBig:=BigMonth;
end;
调用如下“edit1.text:=SmallTOBig(1234567890.1234);”他自动默认小数点后两位
 
edit.text:='货币符号'+formatfloat('0.00',adoquery1.fieldbyname('字段').asinteger);
 
function TForm1.xTOd(i:Real):string;
const
d='零壹贰叁肆伍陆柒捌玖分角元拾佰仟万拾佰仟亿';
var
m,k:string;
j:integer;
begin

k:='';
m:=floattostr(int(i*100));
for j:=length(m)do
wnto 1do

k:=k+d[(strtoint(m[Length(m)-j+1])+1)*2-1]+
d[(strtoint(m[Length(m)-j+1])+1)*2]+d[(10+j)*2-1]+d[(10+j)*2];
xTOd:=k;
end;

调用:
procedure TForm1.Button1Click(Sender: TObject);
var
Sum:real;
begin

sum:=12.34;
showmessage('人民币大写:'+xTOd(Sum));
end;
 
这个函数支持的范围特别大,建议使用,而且运行稳定
function SmallToBig ( szCurrency: string ): string;
vardo
tPos:integer;
szInt:string;
// 小写的整数部分
szFlt:string;
// 小写的小数部分
sInt:string;
// 大写的整数部分
sFlt:string;
// 大写的小数部分
old_inx_num :integer;
inx_num :integer;
inx_unit :integer;
i: integer;
bOnlyFlt:Boolean;
begin
old_inx_Num:=0;
bOnlyFlt:=False;
do
tPos := Pos('.', szCurrency);
ifdo
tPos <> 0 then
begin
szInt := Copy(szCurrency, 0,do
tPos - 1 );
szFlt := Copy(szCurrency,do
tPos + 1, 2);
end
else
begin
szInt := szCurrency;
szFlt := '';
end;
if ( ( szInt = '0' ) and (( szFlt = '00' ) or ( szFlt = '')) ) then
begin
result := '零圆整';
exit;
end;
if ( szInt = '0' ) then
bOnlyFlt := true;
// 如果整数部分为零
if ( (Length(szFlt) <> 2) and (do
tPos <> 0)) then
// 小数点后必须有两位或者根本没有
begin
result := '';
exit;
end;
if ( not bOnlyFlt ) then
// 如果整数部分为零,则不对其进行处理
for i := 0 to Length(szInt) - 1do
begin
inx_num := StrToInt( szInt[ Length(szInt) - i ] );
if i mod 4 = 0 then
begin
inx_unit := i div 4;
if ( inx_num > 0 ) then
// 以下判断处理诸如"壹亿圆",“壹亿亿圆"
if ( (inx_unit > 0) and (inx_unit mod 2 = 0) and
(sInt[1]+sInt[2] = '万') ) then
sInt := t_num[ inx_num ] + t_unit1[ inx_unit ] +
copy(sInt,3,2*(Length(sInt)-1))
else
sInt := t_num[ inx_num ] + t_unit1[ inx_unit ] + sInt
else
// 以下判断处理诸如"壹拾亿圆“,"壹拾亿亿圆"
if ( (inx_unit > 0) and (inx_unit mod 2 = 0) and
(sInt[1]+sInt[2] = '万') ) then
sInt := t_unit1[ inx_unit ] + copy(sInt,3,2*(Length(sInt)-1))
else
sInt := t_unit1[ inx_unit ] + sInt;
end
else
begin
inx_unit := i mod 4 - 1;
if inx_num > 0 then
sInt := t_num[ inx_num ] + t_unit2[ inx_unit ] + sInt
else
if old_inx_num > 0 then
sInt := t_num[ inx_num ] + sInt;
end;
old_inx_num := inx_num;
end;
//处理小数部分
if ( ( szFlt <> '' ) and ( szFlt <> '00' ) ) then
begin
for i := 0 to 1do
begin
inx_num := StrToInt(szFlt[i + 1]);
if (inx_num > 0) then
sFlt := sFlt + t_num[inx_num] + t_unit3
else
if ( i <> 1) then
// 如果"角"为0 "分"是 0, 则忽略)
if ( not bOnlyFlt ) then
// 如果整数为此时为零
sFlt := sFlt + t_num[inx_num];
end;
result := sInt + sFlt+'整';
end
else
begin
result := sInt + '整';
end
end;
 
to 沙_儿,100个亿能正确写出吗???3Q~
 
多人接受答案了。
 
顶部