如何将小写金额转换为大写?
在做报表的时候,统计出一个账单的付费金额(小写),格式为¥,0.00;-¥,0.00(如:¥10,406.05),我写的代码如下:
function TForm1.GetPositionName(value: integer): string;
begin
case value of
-2: result:='分';
-1: result:='角';
//0: result:='圆';
0: result:='';
1: result:='拾';
2: result:='佰';
3: result:='仟';
4: result:='万';
5: result:='十';
6: result:='百';
7: result:='千';
8: result:='亿';
9: result:='拾';
end;
end;
function TForm1.GetBigValue(value: char): string;
begin
case value of
'0': result:='零';
'1': result:='壹';
'2': result:='贰';
'3': result:='叁';
'4': result:='肆';
'5': result:='伍';
'6': result:='陆';
'7': result:='柒';
'8': result:='捌';
'9': result:='玖';
end;
end;
function TForm1.LowertoUpper(LowerStr : Extended) : string;
var
Money: string;
i : integer;
position : integer;
HasLower : Boolean;
addZero : integer;
strMoney : string;
begin
Money := FormatFloat('0.00',LowerStr);
position := -2;
strmoney := '';
addZero := 0;
HasLower := False;
for i:=Length(Money) downto 1 do
begin
case position of
4,8:begin
if HasLower and (AddZero>0) then
begin
strMoney := GetBigValue('0') + strMoney;
HasLower := False;
AddZero := 0;
end;
end;
end;
if Money[i]<>'0' then
begin
if Money[i]<>'.' then
begin
if (addZero>0) and HasLower then
begin
strMoney := GetBigValue('0') + strMoney;
addZero := 0;
end;
case position of
-2,-1,4,8: HasLower := False;
else
HasLower := True;
end;
strMoney := GetBigValue(Money[i]) + GetPositionName(position) + strMoney;
end
else begin
position := position - 1;
strMoney := '圆'+strMoney;
end;
end
else if position >0 then
begin
addZero := addZero + 1;
case position of
0,4,8: begin
strMoney := GetPositionName(position) + strMoney;
end;
end;
end;
position := position + 1;
end;
Result := strMoney;
end;
可是运行后某些特殊的数据不能正常现实,小弟请教各位大哥给出正确的算法,不胜感激!