关于 咋儿把 10234.56 轮换为 壹萬零贰佰叁拾肆圆伍角陆分 十分感谢!,感谢左右顾,不过... (10分)

  • 主题发起人 主题发起人 _ccc
  • 开始时间 开始时间
C

_ccc

Unregistered / Unconfirmed
GUEST, unregistred user!
不是把 10234.56 轮换为 壹萬零仟零贰佰叁拾肆圆伍角陆分
而是把 10234.56 轮换为 壹萬零贰佰叁拾肆圆伍角陆分
 
给你个函数
Function TForm1.SmallToBig(small: real): String;
Var
SmallMonth, BigMonth: String;
wei1, qianwei1 : String[2];
qianwei, dianweizhi, qian: integer;
begin
{----------修改参数值令更精确-------------}
//小数点後的位置,需要的话可以改动-2的值
qianwei := -3;
//转换成货币形式,需要的话小数点後多加几个零
Smallmonth := formatfloat('0.000', 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;
result := bigmonth;
end;
 
[red]居然慢了點[/red][:D]
樓上的就行
 
哈,楼下的,慢了一步吧,哈哈
这样吧,再给你一个
Function 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
begin
K := k + d[(strtoint(m[length(M) - j + 1])) * 2 + 1] +
d[(strtoint(m[length(M) - j + 1])) * 2 + 2] + d[(10 + j) * 2 - 1] +
d[(10 + j) * 2];
end;
Result:=k;
end;
 
这两个函数你用哪个都行
Procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.Text := smalltobig(10234.56);
end;

Procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.Text:=XTOD(10234.56);
end;
 
不要說我照抄嗎,是吧[:D][:D][:D]
自己考慮考慮自己寫也不難的
 
function f_get_jedx(num : string):string;
//得到金额大写

function TForm_main.f_get_jedx(num : string):string;
//得到金额大写
var hz,money : array [0..20] of string;
rmb : boolean;
str,str_tmp,val,num2 : string;
i,il_i,lpos : integer;
begin
rmb := true;
if not rmb then
begin
hz[1]:='一';
hz[2]:='二';
hz[3]:='三';
hz[4]:='四';
hz[5]:='五';
hz[6]:='六';
hz[7]:='七';
hz[8]:='八';
hz[9]:='九';
hz[10]:='十';
hz[11]:='百';
hz[12]:='千';
hz[13]:='万';
hz[14]:='亿';
hz[15]:='点';
end
else
begin
hz[1]:='壹';
hz[2]:='贰';
hz[3]:='叁';
hz[4]:='肆';
hz[5]:='伍';
hz[6]:='陆';
hz[7]:='柒';
hz[8]:='捌';
hz[9]:='玖';
hz[10]:='拾';
hz[11]:='佰';
hz[12]:='仟';
hz[13]:='万';
hz[14]:='亿';
hz[15]:='元';
money[1]:='角';
money[2]:='分';
end;

val := num;
if pos('.',val) <> 0 then
begin
num := copy(val,1,pos('.',val)-1);
//整数
num2 := copy(val,pos('.',val)+1,10);
//小数
end;

str := '';
for i := 1 to length(num)do
begin
str_tmp := copy(num,i,1);
if str_tmp = '1' then
str := str + hz[1];
if str_tmp = '2' then
str := str + hz[2];
if str_tmp = '3' then
str := str + hz[3];
if str_tmp = '4' then
str := str + hz[4];
if str_tmp = '5' then
str := str + hz[5];
if str_tmp = '6' then
str := str + hz[6];
if str_tmp = '7' then
str := str + hz[7];
if str_tmp = '8' then
str := str + hz[8];
if str_tmp = '9' then
str := str + hz[9];
if str_tmp = '0' then
str := str + '';
if str_tmp='0' then
if (copy(str,length(str)-2,2)='零') or (str='') or (i=length(num)) then
str := str
else
str := str + '零'
else
case length(num) -i + 1 of
1 : str := str;
2,6,10 : str := str + hz[10];
3,7,11 : str := str + hz[11];
4,8,12 : str := str + hz[12];
//千
5,13 : str := str + hz[13];
//'万'
9 : str := str + '亿';
end;

if (length(num)-i+1=9) and (copy(num,length(num)-8,1)='0') then
begin
if copy(str,length(str)-2,2)='零' then
str := copy(str,1,length(str)-2);
str := str +'亿';
end;

if (length(num)-i+1=5) and (copy(num,length(num)-4,1)='0') then
begin
if copy(str,length(str)-2,2)='零' then
str := copy(str,1,length(str) - 2);
str := str +'万';
end;
end;

if copy(str,length(str)-2,2)='零' then
str := copy(str,1,length(str) - 2);
lpos := pos('亿万',str);
if lpos <> 0 then
str := copy(str,1,lpos+1)+copy(str,lpos+4,10000);
if pos('.',val)=0 then
if rmb then
f_get_jedx := str+hz[15]
else
f_get_jedx := str;
str := str + hz[15];
//点or 元
il_i := length(num2);
if rmb and (il_I>2) then
il_i := 2;
for i := 1 to il_ido
begin
str_tmp := copy(num2,i,1);
if str_tmp = '1' then
str := str + hz[1];
if str_tmp = '2' then
str := str + hz[2];
if str_tmp = '3' then
str := str + hz[3];
if str_tmp = '4' then
str := str + hz[4];
if str_tmp = '5' then
str := str + hz[5];
if str_tmp = '6' then
str := str + hz[6];
if str_tmp = '7' then
str := str + hz[7];
if str_tmp = '8' then
str := str + hz[8];
if str_tmp = '9' then
str := str + hz[9];
if str_tmp = '0' then
str := str + '零';
if rmb and (copy(str,length(str)-2,2)<>'零') then
str :=str + money;
end;
while copy(str,length(str),2) = '零'do
str := copy(str,1,length(str)-2);
//成对的零消成单个零
i := 3;
while i < length(str)do
begin
if copy(str,i,4) = '零零' then
str := copy(str,1,i-1) + copy(str,i+2,1000);
i := i + 2;
end;
//成对的零消成单个零
i := 3;
while i < length(str)do
begin
if copy(str,i,4) = '零零' then
str := copy(str,1,i-1) + copy(str,i+2,1000);
i := i + 2;
end;
//去掉元和万前面的零
i := 3;
while i < length(str)do
begin
if (copy(str,i,4)='零万') or (copy(str,i,4)='零元') then
str := copy(str,1,i-1) + copy(str,i+2,1000);
i := i + 2;
end;
//改拾零成拾
i := 3;
while i < length(str)do
begin
if (copy(str,i,4)='拾零') then
str := copy(str,1,i+1) + copy(str,i+4,1000);
i := i + 2;
end;
//改百零成拾
i := 3;
while i < length(str)do
begin
if (copy(str,i,4)='佰零') then
str := copy(str,1,i+1) + copy(str,i+4,1000);
i := i + 2;
end;
//改亿万成亿
i := 3;
while i < length(str)do
begin
if (copy(str,i,4)='亿万') then
str := copy(str,1,i+1) + copy(str,i+4,1000);
i := i + 2;
end;

//“元角”处理成“元”
i := 3;
while i < length(str)do
begin
if copy(str,i,4)='元角' then
str := copy(str,1,i+1) + copy(str,i+2,1000);
i := i + 2;
end;
f_get_jedx := str;
end;

//调用函数
edit1.Text := f_get_jedx('10234.56');
 
编写一个收费软件时要用到一个小写金额转换成大写金额的函数,我曾在网上找到一个用Powerbuilder写的函数,长达四五十行之巨,后来我自己用DELPHI写了一个函数,寥寥几行代码就搞定:
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;


 
我也编了一个 请大家指点指点:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var str,Tempstr,ObjStr:string;
Po,Ts1Lth,i:integer;
Ts1,Ts2:TStringList;
begin
Ts1:=Tstringlist.Create;
Ts2:=Tstringlist.Create;
Ts1.CommaText:='万,千,百,十,亿,千,百,十,万,千,百,十, 圆,,角,分';
Ts2.CommaText :='零,壹,贰,叁,肆,伍,陆,柒,捌,玖';
str:=trim(format('%1000.2f',[strtofloat(Edit1.text)]));
Edit1.Text :=str;
Po:=Pos('.',str);
Ts1Lth:=Ts1.Count;
for i:=1 to (po-1)do
begin
Tempstr:=Str;
ObjStr:=ObjStr+Ts2[strtoint(Tempstr)]+Ts1[Ts1Lth-po-3+i]
end;
for i:=2do
wnto 1do
begin
Tempstr:=Copy(str,Length(str)-i+1,1);
if Tempstr='0' then
else
Objstr:=objstr+Ts2[strtoint(Tempstr)]+Ts1[Ts1Lth-i]
end;
while pos('零十',Objstr)<>0do
Objstr:=Copy(objstr,1,pos('零十',Objstr)-1)+'零'+Copy(objstr,pos('零十',Objstr)+4,length(objstr)-pos('零十',Objstr)-3);
while pos('零百',Objstr)<>0do
Objstr:=Copy(objstr,1,pos('零百',Objstr)-1)+'零'+Copy(objstr,pos('零百',Objstr)+4,length(objstr)-pos('零百',Objstr)-3);
while pos('零千',Objstr)<>0do
Objstr:=Copy(objstr,1,pos('零千',Objstr)-1)+'零'+Copy(objstr,pos('零千',Objstr)+4,length(objstr)-pos('零千',Objstr)-3);
while pos('零万',Objstr)<>0do
Objstr:=Copy(objstr,1,pos('零万',Objstr)-1)+'万'+Copy(objstr,pos('零万',Objstr)+4,length(objstr)-pos('零万',Objstr)-3);
while pos('零圆',Objstr)<>0do
Objstr:=Copy(objstr,1,pos('零圆',Objstr)-1)+'圆'+Copy(objstr,pos('零圆',Objstr)+4,length(objstr)-pos('零圆',Objstr)-3);
while pos('零零',Objstr)<>0do
Objstr:=Copy(objstr,1,pos('零零',Objstr)-1)+'零'+Copy(objstr,pos('零零',Objstr)+4,length(objstr)-pos('零零',Objstr)-3);
Label1.Caption :=Objstr;
Ts1.Free;
Ts2.Free;
end;

end.
 
后退
顶部