人民币大写转换(200分)

  • 主题发起人 主题发起人 fangzhou_com
  • 开始时间 开始时间
F

fangzhou_com

Unregistered / Unconfirmed
GUEST, unregistred user!
比如:194.00<br>转换成:X万X仟壹佰玖拾肆圆零角零分<br>恳请做过的大侠教下啊
 
呵呵,很简单,就是将原来的大家习惯的“整”换成“零角零分”,可以实现,不知道满足要求不?如下代码:<br>Function NtoC(n0 :real) :String;<br>&nbsp; Function IIF(b :boolean; s1,s2:string):string;<br>&nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; if b then IIF:=s1 else IIF:=s2;<br>&nbsp; &nbsp; end;<br>&nbsp; Const c = '零壹贰叁肆伍陆柒捌玖◇分角圆拾佰仟万拾佰仟亿拾佰仟万';<br>&nbsp; var L,i,n, code :integer;<br>&nbsp; &nbsp; &nbsp; Z :boolean;<br>&nbsp; &nbsp; &nbsp; s, st,st1 :string;<br>begin<br>&nbsp; s :=FormatFloat( '0.00', n0);<br>&nbsp; L :=Length(s);<br>&nbsp; Z :=n0&lt;1;<br>&nbsp; For i:= 1 To L-3 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Val(Copy(s, L-i-2, 1), n, code);<br>&nbsp; &nbsp; &nbsp; st:=IIf((n=0)And(Z Or (i=9)Or(i=5)Or(i=1)), '', Copy(c, n*2+1, 2))<br>&nbsp; &nbsp; &nbsp; &nbsp; + IIf((n=0)And((i&lt;&gt;9)And(i&lt;&gt;5)And(i&lt;&gt;1)Or Z And(i=1)),'',Copy(c,(i+13)*2-1,2))<br>&nbsp; &nbsp; &nbsp; &nbsp; + st;<br>&nbsp; &nbsp; &nbsp; Z := (n=0);<br>&nbsp; &nbsp; end;<br>&nbsp; Z := False;<br>&nbsp; For i:= 1 To 2 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Val(Copy(s, L-i+1, 1), n, code);<br>&nbsp; &nbsp; &nbsp; st1:= IIf((n=0)And((i=1)Or(i=2)And(Z Or (n0&lt;1))), '', Copy(c, n*2+1, 2))<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ IIf((n&gt;0), Copy(c,(i+11)*2-1, 2), IIf((i=2) Or Z, '','零角零分'))<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ st1;<br>&nbsp; &nbsp; &nbsp; Z := (n=0);<br>&nbsp; &nbsp; end;<br>&nbsp; For i := 1 To Length(st) do If Copy(st, i, 4) = '亿万' Then Delete(st,i+2,2);<br>&nbsp; NtoC := IIf( n0=0, '零', st + st1);<br>End;<br><br>调用:Edit2.Text:=NtoC(StrToFloat(Edit1.Text));
 
以前有过大小写转换的,等给我找找看
 
function FloatToCNStr(sr:real):string;<br>const<br>scCD:array ['0'..'9'] of string[2]=('零','壹','贰','叁','肆','伍','陆','柒','捌','玖');<br>scCU:array [1..7] of string[2]=('万','仟','佰','拾','圆','角','分');<br>var ss,ss1:string; s:byte; sc:char;<br>begin<br>&nbsp; ss1:='';<br>&nbsp; ss:=format('%7d',[round(sr*100)]);<br>&nbsp; for s:=7 downto 1 do begin<br>&nbsp; &nbsp; ss1:=scCU+ss1;<br>&nbsp; &nbsp; sc:=ss;<br>&nbsp; &nbsp; if sc&lt;'0' then ss1:='X'+ss1 else ss1:=scCD[sc]+ss1;<br>&nbsp; end;<br>&nbsp; result:=ss1;<br>end;
 
function TForm1.CurrToChnNum(Currnum: currency): string;<br>function FourNumToChnNum(Str:string;ChnNum:string;var Pre:boolean):string;<br>const<br>&nbsp; digits: array [0..9] of string = ('零','壹','贰','叁','肆',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'伍','陆','柒','捌','玖');<br>var i,j,Len:integer;<br>begin<br>&nbsp; Result := '';<br>&nbsp; Len := Length(str) ;<br>&nbsp; for i:=1 to Len<br>&nbsp; do begin<br>&nbsp; &nbsp; j := Ord(str)-48;<br>&nbsp; &nbsp; //if j=0 then<br>&nbsp; &nbsp; // &nbsp;Pre := True<br>&nbsp; &nbsp; //else begin<br>&nbsp; &nbsp; &nbsp; if Pre then<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := Result + '零';<br>&nbsp; &nbsp; &nbsp; Result := Result + digits[j] + Trim(Copy(ChnNum,(Len - i) * 2+1,2));<br>&nbsp; &nbsp; &nbsp; Pre := False;<br>&nbsp; &nbsp;// end;<br>&nbsp; end;<br>end;<br><br>function StringToChnNum(str:string):string;<br>const ChnNum1='元万亿兆';<br>var i,Len,Len1,Level,Start:integer;<br>&nbsp; s1,s:string;<br>&nbsp; Pre: Boolean;<br>begin<br>&nbsp; Result := '';<br>&nbsp; Len := Pos('.',str)-1;<br>&nbsp; Level := (Len + 3) div 4 ;<br>&nbsp; Len1 := Len mod 4 ;<br>&nbsp; if Len1=0 then Len1 := 4;<br>&nbsp; Start := 1;<br>&nbsp; for i := 1 to Level<br>&nbsp; do begin<br>&nbsp; &nbsp; Pre := False;<br>&nbsp; &nbsp; s := Copy(str,Start,Len1);<br>&nbsp; &nbsp; s1 := FourNumToChnNum(s,' &nbsp;拾佰仟',Pre); &nbsp; &nbsp; // 注意有两个空格<br>&nbsp; &nbsp; if s1&lt;&gt;'' then<br>&nbsp; &nbsp; &nbsp; Result := Result + s1 + Copy(ChnNum1,(Level-i)*2+1,2);;<br>&nbsp; &nbsp; Start := Start + Len1;<br>&nbsp; &nbsp; Len1 := 4;<br>&nbsp; end;<br>&nbsp; if copy(result,length(result)-3,2)='零' then delete(result,length(result)-3,2);<br>&nbsp; Pre := False;<br>&nbsp; s1 := FourNumToChnNum(Copy(str,Len+2,2),'分角',Pre);<br>&nbsp; //if s1 = '' then &nbsp;s1 := '整';<br>&nbsp; Result := Result + s1 ;<br>end;<br>//主程序<br>var s:string;<br>i:integer;<br>begin<br>&nbsp; Currnum:=Currnum;<br>&nbsp; s:=format('%11.2f',[Currnum]);<br>&nbsp; //s:=formatfloat('0.00',currnum);<br>&nbsp; Result := StringToChnNum(Trim(s));<br>&nbsp; //while length(result)&lt;28 do result:=' '+result;<br>end;
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
687
import
I
后退
顶部