数字输出为中文描述(delphi)

unit converttostr;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TNumberStr = string[2];
const
Numbers: array[0..9] of TNumberStr = ( '零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');
ErrorString = 'not in valid range';
Min = 0;
Max = 9999999999;
function RecurseNumber(N: longword): string;
function NumToLetters(Number: real): string;
var
Form1: TForm1;
implementation
{$R *.dfm}
function RecurseNumber(N: longword): string;
var zerostr: string[2];
begin
zerostr := '';
case N of
1..9:
Result := Numbers[N];
10..99:
Result := Numbers[N div 10] + '拾' + RecurseNumber(N mod 10);
100..999:
begin
if (N mod 100 >= 1) and (N mod 100 < 10) then zerostr := '零';
Result := Numbers[N div 100] + '佰' + zerostr + RecurseNumber(N mod 100);
end;
1000..9999:
begin
if (N mod 100 >= 1) and (N mod 1000 < 100) then zerostr := '零';
Result := Numbers[N div 1000] + '仟' + zerostr + RecurseNumber(N mod 1000);
end;
10000..99999999:
begin
if (N mod 100 >= 1) and (N mod 10000 < 1000) then zerostr := '零';
Result := RecurseNumber(N div 10000) + '万' + zerostr + RecurseNumber(N mod 10000);
end;
100000000..2399999999:
begin
if (N mod 100 >= 1) and (N mod 100000000 < 10000000) then zerostr := '零';
Result := RecurseNumber(N div 100000000) + '亿' + zerostr + RecurseNumber(N mod 100000000);
end;
end;
end;
function NumToLetters(Number: real): string;
begin
if (Number >= Min) and (Number <= Max) then
begin
Result := RecurseNumber(round(int(Number))) + '元';
if not(Frac(Number) = 0.00) then
Result := Result + RecurseNumber(Round(Frac(Number)*100)) + '分';
end
else

Raise ERangeError.CreateFmt('%g' + ErrorString + '%g..%g', [Number, Min, Max])ERangeError.CreateFmt('%g' + ErrorString + '%g..%g', [Number, Min, Max]);
end;


procedure TForm1.Button1Click(Sender: TObject);
begin


Edit2.Text := NumToLetters(Strtofloat(Edit1.text));
end;


end.



来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/166523/viewspace-204046/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/166523/viewspace-204046/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值