function FourNumToChnNum(Str:string;ChnNum:string;var Pre:boolean):string;
const
ChnNum2='零壹贰叁肆伍陆柒捌玖';
var
i,j,Len:integer;
begin
Result := '';
Len := Length(str) ;
for i:=1 to Len do begin
j := Ord(str[i])-48;
if j=0 then
Pre := True
else begin
if Pre then
Result := Result + '零';
Result := Result + Copy(ChnNum2,j*2+1,2) + Trim(Copy(ChnNum,(Len - i) * 2+1,2));
Pre := False;
end;
end;
end;
function StringToChnNum(str:string):string;
const
ChnNum1='圆万亿兆';
var
i,Len,Len1,Level,Start:integer;
s1,s:string;
Pre: Boolean;
begin
Result := '';
Len := Pos('.',str)-1;
Level := (Len + 3) div 4 ;
Len1 := Len mod 4 ;
if Len1=0 then
Len1 := 4;
Start := 1;
Pre := False;
for i := 1 to Level do begin
s := Copy(str,Start,Len1);
s1 := FourNumToChnNum(s,' 拾佰仟',Pre); // 注意有两个空格
if s1<>'' then
Result := Result + s1 + Copy(ChnNum1,(Level-i)*2+1,2);;
Start := Start + Len1;
Len1 := 4;
end;
s1 := FourNumToChnNum(Copy(str,Len+2,2),'分角',Pre);
if s1 = '' then
s1 := '整';
Result := Result + s1 ;
end;
function RealToChnNum(realnum:real;Width:integer):string;
var
s:string;
begin
Str(realnum:Width:2,s);
Result := StringToChnNum(Trim(s));
end;
以下是一个Delphi源码,希望对你有帮助,虽然只能转换整形
function ChinaNum(X: Int64):string;
const
positions:Array[1..4] of string=( '仟','佰','拾','' );//四位一组的后缀
digits :Array[0..9] of string=( '零', '壹', '贰', '叁', '肆',
'伍', '陆', '柒', '捌', '玖');//大写定义
var
S,tmp: string;
Str: Array[1..4] of String;
Num: Array[1..4] of Integer;
ChinaNum: Array[1..4] of String;
I,J,K: Integer;
begin
if X>9999999999999999 then begin
Result:= '超出范围';
Exit;
end;
S:=format('%16u',[x]);//将数字转化为16位长度的字符串(不足添空格)
result:='';//返回值
ChinaNum[1]:='京';//单位
ChinaNum[2]:='亿';
ChinaNum[3]:='万';
ChinaNum[4]:='';
For I:= 1 to 4 do begin
Str[I]:= Copy(S, (I shl 2)-3,4);//字符串拷贝从(i shl 2)-3的位置开始的4个.i shl 2 表示左移2位
if Str[I]='0000' then begin
Str[I]:=' ';
Continue;
end
else begin
J:=Pos('000',Str[I]);
case J of
0: begin
J:=Pos('00', Str[I]);
Case J of
0:;
else Str[I,J]:=' ';
end;
end;
else begin
Str[I,J]:=' ';
Str[I,J+1]:=' ';
end;
end;
if Str[I,4]='0' then
Str[I,4]:=' ';
end;
end;
For I:= 1 to 4 do begin
For J:= 4 Downto 1 do begin
case Str[I,J] of
'0': ChinaNum[I]:='零'+ChinaNum[I];
'1'..'9': begin
ChinaNum[I]:=Digits[Ord(Str[I,J])-48]+Positions[J]+ChinaNum[I];//Ord函数 取字符ASCII码
end;
else;
end;
end;
if (I=4)Or(Length(ChinaNum[I])>2) then begin
Result:= Result+ ChinaNum[I];
end;
end;
if Result='' then
Result:='零';
end;