T
tobey
Unregistered / Unconfirmed
GUEST, unregistred user!
我在fastreport报表里用到一个将金额数字转换成大写的函数(Funtion),我把它写在Memo
中的Text Editor中,程序如下:
Function RealToChineseMoneyString(Amount : real) : String;
var
Dollars : LongInt;
cents : Integer;
const EPSILON = 0.0000001;
function Num2Str(Num: LongInt): String;
Const Ten = 10;
Hundred = 100;
Thousand = 1000;
TenThousand = 10000;
HundredMillion = 100000000;
begin
if Num >= HundredMillion then
begin
if (Num mod HundredMillion) = 0 then
Result := Num2Str(Num div HundredMillion) + '货'
else if (Num mod HundredMillion) < (HundredMillion/10) then
Result := Num2Str(Num div HundredMillion) + '货箂' +
Num2Str(Num mod HundredMillion)
else
Result := Num2Str(Num div HundredMillion) + '货' +
Num2Str(Num mod HundredMillion);
end
else if Num >= TenThousand then
begin
if (Num mod TenThousand) = 0 then
Result := Num2Str(Num div TenThousand) + '窾'
else if (Num mod TenThousand) < (TenThousand/10) then
Result := Num2Str(Num div TenThousand) + '窾箂' +
Num2Str(Num mod TenThousand)
else
Result := Num2Str(Num div TenThousand) + '窾' +
Num2Str(Num mod TenThousand);
end
else if Num >= thousand then
begin
if (Num mod thousand) = 0 then
Result := Num2Str(Num div thousand) + '?'
else if (Num mod thousand) < (thousand/10) then
Result := Num2Str(Num div Thousand) + '?箂' +
Num2Str(Num mod Thousand)
else
Result := Num2Str(Num div Thousand) + '?' +
Num2Str(Num mod Thousand);
end
else if Num >= hundred then
begin
if (Num mod hundred) = 0 then
Result := Num2Str(Num div hundred) + 'ㄕ'
else if (Num mod hundred) < (hundred/10) then
Result := Num2Str(Num div hundred) + 'ㄕ箂' +
Num2Str(Num mod hundred)
else
Result := Num2Str(Num div hundred) + 'ㄕ' +
Num2Str(Num mod hundred);
end
else if Num >= Ten then
begin
if (Num mod Ten) = 0 then
Result := Num2Str(Num div Ten) + '珺'
else if (Num mod Ten) < (Ten/10) then
Result := Num2Str(Num div Ten) + '珺' +
Num2Str(Num mod Ten)
else
Result := Num2Str(Num div Ten) + '珺' +
Num2Str(Num mod Ten);
end
else
begin
case Num of
0: Result := '箂';
1: Result := '滁';
2: Result := '禠';
3: Result := '把';
4: Result := '竩';
5: Result := 'ヮ';
6: Result := '嘲';
7: Result := '琺';
8: Result := '?';
9: Result := '╤';
end;
end;
end {Num2Str};
begin
Dollars := Trunc(Amount);
cents := Round(100*Frac(Amount));
if not ((Dollars > EPSILON) or (Cents > EPSILON)) then
begin
Result := '箂';
Exit;
end;
if Dollars > EPSILON then
Result := Num2Str(Dollars);
Result := Result + '蛾';
if cents > EPSILON then
Result := Result + Num2Str(cents) + '?'
else
Result := Result + 'タ';
end;
然后在上面调用如下:
[ RealToChineseMoneyString(table1.fieldByName('TotalAmount).AsFloat)]
为什么会出错呢??
希望各位智囊高手指正一下,在线等!!!
中的Text Editor中,程序如下:
Function RealToChineseMoneyString(Amount : real) : String;
var
Dollars : LongInt;
cents : Integer;
const EPSILON = 0.0000001;
function Num2Str(Num: LongInt): String;
Const Ten = 10;
Hundred = 100;
Thousand = 1000;
TenThousand = 10000;
HundredMillion = 100000000;
begin
if Num >= HundredMillion then
begin
if (Num mod HundredMillion) = 0 then
Result := Num2Str(Num div HundredMillion) + '货'
else if (Num mod HundredMillion) < (HundredMillion/10) then
Result := Num2Str(Num div HundredMillion) + '货箂' +
Num2Str(Num mod HundredMillion)
else
Result := Num2Str(Num div HundredMillion) + '货' +
Num2Str(Num mod HundredMillion);
end
else if Num >= TenThousand then
begin
if (Num mod TenThousand) = 0 then
Result := Num2Str(Num div TenThousand) + '窾'
else if (Num mod TenThousand) < (TenThousand/10) then
Result := Num2Str(Num div TenThousand) + '窾箂' +
Num2Str(Num mod TenThousand)
else
Result := Num2Str(Num div TenThousand) + '窾' +
Num2Str(Num mod TenThousand);
end
else if Num >= thousand then
begin
if (Num mod thousand) = 0 then
Result := Num2Str(Num div thousand) + '?'
else if (Num mod thousand) < (thousand/10) then
Result := Num2Str(Num div Thousand) + '?箂' +
Num2Str(Num mod Thousand)
else
Result := Num2Str(Num div Thousand) + '?' +
Num2Str(Num mod Thousand);
end
else if Num >= hundred then
begin
if (Num mod hundred) = 0 then
Result := Num2Str(Num div hundred) + 'ㄕ'
else if (Num mod hundred) < (hundred/10) then
Result := Num2Str(Num div hundred) + 'ㄕ箂' +
Num2Str(Num mod hundred)
else
Result := Num2Str(Num div hundred) + 'ㄕ' +
Num2Str(Num mod hundred);
end
else if Num >= Ten then
begin
if (Num mod Ten) = 0 then
Result := Num2Str(Num div Ten) + '珺'
else if (Num mod Ten) < (Ten/10) then
Result := Num2Str(Num div Ten) + '珺' +
Num2Str(Num mod Ten)
else
Result := Num2Str(Num div Ten) + '珺' +
Num2Str(Num mod Ten);
end
else
begin
case Num of
0: Result := '箂';
1: Result := '滁';
2: Result := '禠';
3: Result := '把';
4: Result := '竩';
5: Result := 'ヮ';
6: Result := '嘲';
7: Result := '琺';
8: Result := '?';
9: Result := '╤';
end;
end;
end {Num2Str};
begin
Dollars := Trunc(Amount);
cents := Round(100*Frac(Amount));
if not ((Dollars > EPSILON) or (Cents > EPSILON)) then
begin
Result := '箂';
Exit;
end;
if Dollars > EPSILON then
Result := Num2Str(Dollars);
Result := Result + '蛾';
if cents > EPSILON then
Result := Result + Num2Str(cents) + '?'
else
Result := Result + 'タ';
end;
然后在上面调用如下:
[ RealToChineseMoneyString(table1.fieldByName('TotalAmount).AsFloat)]
为什么会出错呢??
希望各位智囊高手指正一下,在线等!!!