function changermb(const strrmb:string):string;
vartxt,strhighlevel:string;
i,n,m,ilen,ipos:integer; //n記錄整數部分長度,m記錄分數部分長度
strarray,strlevel:array of string;
p:pchar;
ispoint:boolean;//判斷是否有小數點
begin
ispoint:=false;
result:='';
ipos:=0;
m:=0;
txt:=trim(strrmb);
i:=1;
p:=pchar(txt);
//去除開頭的0,以及.
if ((txt[1]='0') and (txt[2]<>'.')) or (txt[1]='.') then
begin
showmessage('第1位不能為0或者是.,退出操作');
exit;
end;
//檢查字元的合法性
while (i
begin
if (p^>'9') or ((p^<'0') and (p^<>'.')) then //ord('.')=46
begin
showmessage(pchar('第'+inttostr(i)+'位包含非數字字元,將退出操作'));
exit;
end;
if p^='.' then
if ispoint then
begin
showmessage('太多小數點,將退出!');
exit;
endelse
begin
ipos:=i;
ispoint:=true;
end;
inc(p);
inc(i);
end;//while
ilen:=length(txt);
if ispoint then
begin
n:=ipos-1;
m:=ilen-ipos;
endelse
n:=ilen;
//判斷是否超過萬,或億
if m>3 then
begin
showmessage('小數點後位數超過3,無法轉換!');
exit;
end;
setlength(strarray,ilen+8);
setlength(strlevel,ilen+8);
for i:=ilen downto 1 do
begin
if txt[i]<>'.' then
case strtoint(txt[i]) of
1:strarray[i]:='壹';
2:strarray[i]:='貳';
3:strarray[i]:='叄';
4:strarray[i]:='肆';
5:strarray[i]:='伍';
6:strarray[i]:='陸';
7:strarray[i]:='柒';
8:strarray[i]:='捌';
9:strarray[i]:='玖';
0:begin
strarray[i]:='零';
if i
if (strarray[i+1]= '') or (strarray[i+1]= '零') then
begin
//strarray[i+1]:= '';
strarray[i]:= '';
end;
if i=n then strarray[i]:='';
strlevel[i]:='';
end;
end; //case
end;
//先處理 小數點部分
if m>0 then
begin
for i:=m downto 1 do
begin
strlevel[ipos+i]:='';
case i-1 of
0:if txt[ipos+i]='0' then
strarray[ipos+i]:=''
else
strlevel[ipos+i]:='角';
1:if txt[ipos+i]='0' then
strarray[ipos+i]:=''
else
strlevel[ipos+i]:='分';
2:if txt[ipos+i]='0' then
strarray[ipos+i]:=''
else strlevel[ipos+i]:='釐';
end;
result:=strarray[ipos+i]+strlevel[ipos+i]+result;
end;
end;
if ispoint and (txt[ipos-1]='0') and (n=1) then
result:=result+'' //如果少於1塊時,不要顯示元。
else
result:='元'+result;
for i:=n downto 1 do
begin
case n-i of
0,4,8,12: strlevel[i]:='';
1,5,9,13: strlevel[i]:='拾';
2,6,10,14: strlevel[i]:='佰';
3,7,11,15: strlevel[i]:='仟';
end; //case
if (txt[i]='0') then strlevel[i]:='';
//要處理零 以及加上萬、億
if n-i=4 then
begin
if strarray[i]='零' then strarray[i]:='';
result:=strarray[i]+strlevel[i]+'萬'+result
endelse if n-i=8 then
begin
if strarray[i]='零' then strarray[i]:='';
result:=strarray[i]+strlevel[i]+'億'+result
end //begin
else if n-i=12 then
begin
if strarray[i]='零' then strarray[i]:='';
result:=strarray[i]+strlevel[i]+'兆'+result
end //begin
else
result:=strarray[i]+strlevel[i]+result;
end; //for
result := result + '整';
end;
人民幣小寫轉大寫
package day00 public class moneyelse result result.replaceall 零角 零 result result.replaceall 零分 零 result result.replaceall 角零 角 if result.equals 零零 ret...
人民幣小寫轉大寫
c code 例如 new money 200 tostring 貳佰元 namespace skyiv.util catch system.console.writeline 大寫 newmoney m 該類過載的 tostring 方法返回的是大寫金額字串 class money 建構函式 pu...
人民幣小寫轉大寫
小寫金額轉成大寫。param input return public static string numtochinese string input catch exception e int len 0 if temp.indexof 1 len temp.length else len temp...