Delphi:
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)-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;
Visual FoxPro:
FUNCTION RealToChnNum
PARAMETER PnRealNum
RETURN StringToChnNum(ALLTRIM(TRANSFORM(PnRealNum,'@R')))
ENDFUNC
FUNCTION StringToChnNum
PARAMETER PcStr
LOCAL ChnNum1,I,LnLen,LnLen1,LnLevel,LnStart,LlPre,S1,S,LcResult
STORE '' TO LcResult,S1,S
ChnNum1='圆万亿兆'
LnLen=AT('.',PcStr)-1
LnLevel=INT((LnLen+3) /4)
LnLen1=MOD(LnLen,4)
IF LnLen1=0
LnLen1=4
ENDIF
LnStart=1
LlPre=.F.
FOR I=1 TO LnLevel
S=SUBSTR(PcStr,LnStart,LnLen1)
S1=FourNumToChnNum(s,' 拾佰仟',LlPre) && 注意有两个空格
IF ! EMPTY(S1)
LcResult=LcResult+S1+SUBSTR(ChnNum1,(LnLevel-i)*2+1,2)
ENDIF
LnStart=LnStart+LnLen1
LnLen1=4
NEXT
S1=FourNumToChnNum(SUBSTR(PcStr,LnLen+2,2),'分角',LlPre)
IF EMPTY(S1)
S1='整'
ENDIF
RETURN LcResult+S1
ENDFUNC
FUNCTION FourNumToChnNum
PARAMETER PcStr,PcChnNum,PlPre
LOCAL LcChnNum2,i,j,LnLen,LcResult
LcChnNum2='零壹贰叁肆伍陆柒捌玖'
LcResult=''
LnLen=LEN(PcStr)
FOR I=1 TO LnLen
j=ASC(SUBSTR(PcStr,i,1))-48
IF j=0
PlPre=.T.
ELSE
IF PlPre
LcResult=LcResult+ '零'
ENDIF
LcResult=LcResult+SUBSTR(LcChnNum2,J*2+1,2)+ALLTRIM(SUBSTR(PcChnNum,(LnLen-i)*2+1,2))
PlPre=.F.
ENDIF
NEXT
RETURN LcResult
ENDFUNC