这有程序: function FloatToCCurrency( eSender: Extended ): string; const Number: array [0..9] of string[2] = ( '零','壹','贰',.......'玖' ); MonetaryUnit: array [0..14] of string[2] = ('万','千','佰','拾','亿','千','佰','拾','万','千','百','拾','元','角','分'); var NewMoney: double; p: string[40]; Index, len, flag: longint; begin NewMoney := abs( eSender ); if NewMoney > 100000000000.00 then begin result := FloatAsComma( NewMoney, False ); exit; end; if NewMoney < 0.01 then begin result := '零'; exit; end; if eSender < 0 then result := '负' else result := ''; flag := 1; p := format('%.0f', [ NewMoney*100 ]); len := length(p); for Index := 15-len to 14 do begin if (p[Index-14+len] <> '0') then begin result := result + Number[ StrToIntDef(p[Index-14+len],0)]; result := result + MonetaryUnit[Index]; end else begin if Index = 5 then begin if (p[Index-13+len] <> '0') or (p[Index-12+len] <> '0') then result := result + MonetaryUnit[Index+3]; flag := 0; end else if ( Index = 12 )or( ( Index = 8 )and ( flag = 1)) or ( Index = 4) then result := result + MonetaryUnit[Index]; if (p[Index-13+len] <> '0') and ( Index <> 14 ) then result := result + Number[ StrToInt(p[Index-14+len])]; end; end; if p[len] = '0' then result := result + '整'; end; //FloatAsComma函数,负责数字金额显示 function FloatAsComma( eSender: Extended; bExpand: boolean ): string; begin if bExpand then result := formatfloat( '0.000', abs( eSender ) ) else result := formatfloat( '0.00', abs( eSender ) ); result := StrAsComma( copy( result, 0, pos( '.', result ) - 1)) + copy( result, pos( '.', result ), length( result )); if eSender < 0 then result := '-' + result; end;
[email protected]
function FloatToCCurrency( eSender: Extended ): string;
const
Number: array [0..9] of string[2] =
( '零','壹','贰',.......'玖' );
MonetaryUnit: array [0..14] of string[2] =
('万','千','佰','拾','亿','千','佰','拾','万','千','百','拾','元','角','分');
var
NewMoney: double;
p: string[40];
Index, len, flag: longint;
begin
NewMoney := abs( eSender );
if NewMoney > 100000000000.00 then
begin
result := FloatAsComma( NewMoney, False );
exit;
end;
if NewMoney < 0.01 then
begin
result := '零';
exit;
end;
if eSender < 0 then result := '负'
else result := '';
flag := 1;
p := format('%.0f', [ NewMoney*100 ]);
len := length(p);
for Index := 15-len to 14 do
begin
if (p[Index-14+len] <> '0') then
begin
result := result + Number[ StrToIntDef(p[Index-14+len],0)];
result := result + MonetaryUnit[Index];
end else
begin
if Index = 5 then
begin
if (p[Index-13+len] <> '0') or (p[Index-12+len] <> '0') then
result := result + MonetaryUnit[Index+3];
flag := 0;
end else
if ( Index = 12 )or( ( Index = 8 )and ( flag = 1)) or ( Index = 4) then
result := result + MonetaryUnit[Index];
if (p[Index-13+len] <> '0') and ( Index <> 14 ) then
result := result + Number[ StrToInt(p[Index-14+len])];
end;
end;
if p[len] = '0' then result := result + '整';
end;
//FloatAsComma函数,负责数字金额显示
function FloatAsComma( eSender: Extended; bExpand: boolean ): string;
begin
if bExpand then
result := formatfloat( '0.000', abs( eSender ) ) else
result := formatfloat( '0.00', abs( eSender ) );
result := StrAsComma( copy( result, 0, pos( '.', result ) - 1))
+ copy( result, pos( '.', result ), length( result ));
if eSender < 0 then result := '-' + result;
end;