索求将数字转换为大写的函数(100分)

  • 主题发起人 主题发起人 王建伟
  • 开始时间 开始时间

王建伟

Unregistered / Unconfirmed
GUEST, unregistred user!
索求将数字转换为大写的函数,小数点后保留两位,要求能输入比较大的数,如
1111111111111111111111111111111.25
 
查,有这样的帖子,很详细的代码
 
是,但超过万亿就有问题,不信你试试
 
请问超过万亿的机会?谢谢!
除非是银行使用
 
做程序不能只图简单,各种情况都要考虑到,你说是不是,如果企业销售额上千亿,10年以后呢
 
我自己写的一个。 只是到了亿。供你参考吧
//************************ 转换阿拉伯数字为中文大写金额 ****************************//
function enum2cnum(enum: string): string;
//转化英文数字为中文钱币文字
var
n: integer;
begin
n := strtoint(enum);
case n of
0: Result := '零';
1: Result := '壹';
2: Result := '贰';
3: Result := '叁';
4: Result := '肆';
5: Result := '伍';
6: Result := '陆';
7: Result := '柒';
8: Result := '捌';
9: Result := '玖';
end;
end;

function Md(i: integer): string;
//根据给出的货币位数生成中文货币数量级
begin
case i of
- 4: Result := '钱';
- 3: Result := '厘';
- 2: Result := '分';
- 1: Result := '角';
0: Result := '';
1: Result := '元';
2: Result := '拾';
3: Result := '佰';
4: Result := '仟';
5: Result := '万';
6: Result := '拾';
7: Result := '佰';
8: Result := '仟';
9: Result := '亿';
10: Result := '拾';
11: Result := '佰';
12: Result := '仟';
//... and so on
end;
end;

function c2e(aMoney: Currency): string;
var b: Boolean;
c1: integer;
c2: Real;
r1, r2: string;
begin
b := false;
if aMoney < 0 then
begin
b := True;
aMoney := 0 - aMoney;
end;
c1 := trunc(aMoney);
c2 := aMoney - c1;
r1 := c2e1(c1);
if c2 <> 0 then
r2 := c2e2(c2)
else
r2 := '整';
Result := r1 + r2;
if b then
Result := '负' + Result;
end;

function tt(i: Integer): Integer;
var k: integer;
begin
Result := 1;
while i > 0do
begin
Result := Result * 10;
dec(i);
end;
end;

function c2e1(aMoney: Integer): string;
var b: Boolean;
i: Integer;
a1, a2, r1, r2: string;
c1: Integer;
c2: real;
t: Integer;
begin
a1 := inttostr(aMoney);
i := 1;
if length(a1) = 1 then
begin
Result := enum2cnum(a1) + md(length(a1));
exit;
end;
Result := enum2cnum(a1) + md(length(a1));
//判断跳位
t := StrToInt(a1) - StrToInt(a1[1]) * tt(length(a1) - 1);
if (t < tt(length(a1) - 2)) and (t <> 0) then
Result := Result + '零'
else
if t = 0 then
Result := Result + '元';
if t > 0 then
Result := Result + c2e1(t);
end;

function c2e2(aMoney: Currency): string;
var a1, a2, r2: string;
i: integer;
begin
a1 := currtostr(aMoney);
a2 := copy(a1, 3, length(a1));
//去掉0和小数点符号
i := length(a2);
while i > 0do
begin
r2 := r2 + enum2cnum(a2[length(a2) - i + 1])
+ Md(-length(a2) + i - 1);
dec(i);
end;
Result := r2;
end;

//用法: 调用 Convert_Money_E2C(aMoney : Currency):String;
function Convert_Money_E2C(aMoney: Currency): string;
begin
Result := c2e(aMoney);
end;

//************************ 转换阿拉伯数字为中文大写金额结束 ****************************//
 
黄凯写了个这样的控件,CSDN上有。老王的也挺好!
 
做的好哟真棒!
 
...
王寒松老兄的有bug:
10101001 得到: 壹仟零壹拾零壹仟零壹元整 (没有“万”字)
--------------------------------------------------------------
看我的(我的要小于一万亿,最小到分,没有到厘):
需要uses math;
function ToChineseMoney(num:double):string;
const
digit:array[0..9] of string=('零','壹','贰','叁','肆','伍','陆','柒','捌','玖');
decade:array[0..13] of string=('分','角','元','拾','百','千','万','拾','百','千','亿','拾','百','千');
var
intpart,power10:int64;
d,i:integer;
n:0..9;
last0,band0:boolean;
begin
if(num<0.01)then
begin
result:=digit[0]+'元整';
exit;
end;
d:=trunc(log10(num));
if(d>11)then
raise Exception.Create('超过了能翻译的位数(必须小于1万亿)');
intpart:=Trunc(num*100);
d:=trunc(log10(intpart));
power10:=1;
for i:=1 to d do
power10:=power10*10;
result:='';
last0:=false;
band0:=true;
while d>=0do
begin
n:=integer(intpart div power10);
band0:=band0 and (n=0);
if(n<>0)then
begin
if(last0)then
result:=result+digit[0]+digit[n]+decade[d]
else
result:=result+digit[n]+decade[d];
last0:=false;
end
else
begin
if(d>5)then
begin
last0:=true;
if ((d-2) mod 4)=0 then
if(not band0)then
result:=result+decade[d];
end
else
if(d=2)and(result<>'')then
begin
result:=result+decade[2];
last0:=false;
end
else
last0:=true;
end;
if((d-2)mod 4)=0 then
band0:=true;
intpart:=intpart mod power10;
power10:=power10 div 10;
d:=d-1;
end;
if(result<>'')then
result:=result+'整';
end;

 
补充,我的需要uses math
 
有很多控件,
 
hehe,我刚贴出来。pipi就完成了测试.
这个函数我3年前写的。 因为是用在打印发票上, 我的客户还没有开过超1000万的
发票。 哈, 我也一直没发现
 
to王寒松
测试一下这个数:1011.01
结果为1千01拾1元整。
 
function ToChineseMoney(num:double):string;
const
digit:array[0..9] of string=('零','壹','贰','叁','肆','伍','陆','柒','捌','玖');
decade:array[0..13] of string=('分','角','元','拾','百','千','万','拾','百','千','亿','拾','百','千');
var
intpart,power10:int64;
d,i:integer;
n:0..9;
last0,band0:boolean;
begin
if(num<0.01)then
begin
result:=digit[0]+'元整';
exit;
end;
d:=trunc(log10(num));
if(d>11)then
raise Exception.Create('超过了能翻译的位数(必须小于1万亿)');
intpart := Round(num * 100)//intpart:=Trunc(num*100);
下同
 
有没有黄凯写了个这样的控件,哪里下载?
 
hujunyi, 你乱改我的程序干嘛,后面的厘都是要舍去的,不管是9厘还是1厘,
哪有四舍五入的道理
 
我这儿有,你要我发给你
说EMAIL
 
to funboy88
你有黄凯写的那有函数呀!给我发一个吧!
s_j_f@etang.com谢谢你
 
后退
顶部