TommyYe
一般會員
發表:2 回覆:1 積分:0 註冊:2002-06-09
發送簡訊給我
|
請問名位,如何將數字5555.55轉為大寫(伍万伍仟伍佰伍十伍角伍分)的字串,有沒有控件可以處理?
|
fengcheng
一般會員
發表:17 回覆:21 積分:7 註冊:2002-04-23
發送簡訊給我
|
(* -------------------------------------------------- *)
(* 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;
|
TommyYe
一般會員
發表:2 回覆:1 積分:0 註冊:2002-06-09
發送簡訊給我
|
引言: (* -------------------------------------------------- *)
(* 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; 您好:(fengchen)
您提供的方法我試過,并可以通過運行.多謝!
|