全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:3402
推到 Plurk!
推到 Facebook!

阿拉伯數字變大寫漢字

答題得分者是:shinjie
zch2002115
一般會員


發表:24
回覆:15
積分:7
註冊:2004-11-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-10-07 13:33:03 IP:210.75.xxx.xxx 未訂閱
請問高手: 我想要在控件edit1上輸入阿拉伯數字,相應的大寫漢字反應到edit2上,該怎麼做呢? 例如edit1中輸1234.56 edit2自動跳出 壹千貳百參拾肆點伍陸 請指教! 謝謝!!!
shinjie
資深會員


發表:12
回覆:275
積分:287
註冊:2003-03-19

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-10-07 13:49:28 IP:203.73.xxx.xxx 未訂閱
//參考這個錢達智先生所寫的函式:    (* -------------------------------------------------- *) 
(* Num2BCNum 將阿拉伯數字轉成中文<<大寫>>數字字串 
(* 使用示例: 
(* Num2BCNum(10002.34) ==> 壹萬零貳點參肆
(*
(* Author: Wolfgang Chien 
(* Date: 1996/08/04 
(* Update Date: 
(* -------------------------------------------------- *) 
function Num2BCNum(dblArabic: double): string; 
const 
_ChineseNumeric = '零壹貳參肆伍陸柒捌玖';
var 
sArabic: string; 
sIntArabic: string; 
iPosOfDecimalPoint: integer; 
i: integer; 
iDigit: integer; 
iSection: integer; 
sSectionArabic: string; 
sSection: string; 
bInZero: boolean; 
bMinus: boolean;     (* 將字串反向, 例如: 傳入 ’1234’, 傳回 ’4321’ *) 
function ConvertStr(const sBeConvert: string): string;
var 
x: integer; 
begin 
Result := '';
for x := Length(sBeConvert) downto 1 do 
AppendStr(Result, sBeConvert[x]); 
end; { of ConvertStr } 
begin 
Result := '';
bInZero := True; 
sArabic := FloatToStr(dblArabic); (* 將數字轉成阿拉伯數字字串 *) 
if sArabic[1] = '-' then
begin 
bMinus := True; 
sArabic := Copy(sArabic, 2, 254); 
end 
else 
bMinus := False; 
iPosOfDecimalPoint := Pos('.', sArabic); (* 取得小數點的位置 *)    (* 先處理整數的部分 *) 
if iPosOfDecimalPoint = 0 then 
sIntArabic := ConvertStr(sArabic) 
else 
sIntArabic := ConvertStr(Copy(sArabic, 1, iPosOfDecimalPoint - 1)); 
(* 從個位數起以每四位數為一小節 *) 
for iSection := 0 to ((Length(sIntArabic) - 1) div 4) do 
begin 
sSectionArabic := Copy(sIntArabic, iSection * 4   1, 4); 
sSection := '';
(* 以下的 i 控制: 個十百千位四個位數 *) 
for i := 1 to Length(sSectionArabic) do 
begin 
iDigit := Ord(sSectionArabic[i]) - 48; 
if iDigit = 0 then 
begin 
(* 1. 避免 ’零’ 的重覆出現 *) 
(* 2. 個位數的 0 不必轉成 ’零’ *) 
if (not bInZero) and (i <> 1) then sSection := '零'   sSection;
bInZero := True; 
end 
else 
begin 
case i of 
2: sSection := '拾'   sSection;
3: sSection := '佰'   sSection;
4: sSection := '仟'   sSection;
end; 
sSection := Copy(_ChineseNumeric, 2 * iDigit   1, 2)   
sSection; 
bInZero := False; 
end; 
end;     (* 加上該小節的位數 *) 
if Length(sSection) = 0 then 
begin 
if (Length(Result) > 0) and (Copy(Result, 1, 2) <> '零') then
Result :='零'   Result;
end 
else 
begin 
case iSection of 
0: Result := sSection; 
1: Result := sSection   '萬'   Result;
2: Result := sSection  '億'   Result;
3: Result := sSection  '兆'   Result;
end; 
end; 
end;     (* 處理小數點右邊的部分 *) 
if iPosOfDecimalPoint > 0 then 
begin 
AppendStr(Result, '點');
for i := iPosOfDecimalPoint   1 to Length(sArabic) do 
begin 
iDigit := Ord(sArabic[i]) - 48; 
AppendStr(Result, Copy(_ChineseNumeric, 2 * iDigit   1, 2)); 
end; 
end;     (* 其他例外狀況的處理 *) 
if Length(Result) = 0 then Result := '零';
if Copy(Result, 1, 2) = '點' then Result := '零'   Result;    (* 是否為負數 *) 
if bMinus then Result := '負'   Result;
end;
========================================= 程式有問題並不可怕,最怕是不知問題出在那 不知問題在那不可怕,更怕是不知如何問問題 寫程式要從最簡單的開始
------
我將在茫茫人海中尋訪我唯一之靈魂伴侶。
得之;我幸。不得;我命。
系統時間:2024-05-19 13:33:05
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!