⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 小写金额转换成大写中文.txt

📁 是一部详细介绍了DELPHI的经典著作
💻 TXT
字号:
小写金额转换成大写中文:
1首先在Form1的私有声明中加入一个函数声明
private
{private declarations}
function conert(money:real):string;
2编写其代码
function TForm1.convert(money:real):string;
var
 smallmode:string;
 bigchar,powerchar:string[2];
 power,dotpos,i:integer;
begin
 //变量power用来记录当前正在转换的字符的权值(小数点后面是负值)
power:=-2;
 //将浮点型金额格式转化成字符串smallmode,小数点后面至少保持两位数
smallmode:=formatfloat('0.00',money);
 //获取小数点在字符串中的位置
 //在pos函数前面加一个前缀system是为了避免编译时的函数冲突
dotpos:=system.pos('.',smallmode);
 //从字符串smallmode右端开始依次转换字符
for i:=length(smallmode) downto 1 do begin
//遇到小数点则不用转换
if i=dopos then continue;
 //把字符串最右边的字符作为当前字符并把它转换成整数
case strtoint(copy(smallmode,i,1)) of
  //根据这个整数值把0-9转换成相应的大写字符
  //由于一个汉字需要两个字节来存储,因此bigchar是两个字符的字符数组变量
 1:bigchar:='壹';
 2:bigchar:='贰';
 3:bigchar:='叁';
 4:bigchar:='肆';
 5:bigchar:='伍';
 6:bigchar:='陆';
 7:bigchar:='柒';
 8:bigchar:='捌';
 9:bigchar:='玖';
 0:bigchar:='零';
end;
//根据权值确定相应的金额单位名称
case power of 
-3:powerchar:='厘';
-2:powerchar:='分';
-1:powerchar:='角';
 0:powerchar:='元';
//'拾'将可能重复出现在1,5,9们上
//同样,'佰','仟','万'甚至是'亿'都不得可能重复出现在不同的位置
1,5,9:powerchar:='拾';
2,6,10:powechar:='佰';
3,7,11:powerchar:='仟';
4,12:powerchar:='万';
8:powerchar:='亿';
end;
//使权值提高一位
inc(power);
//把当前大写字符和金额单位附加在上次的转换结果里成为新的转换结果
result:bigchar+powerchar+result;
//result是delphi中新添加的黑认函数变量,表示函数的返回值
end;
end;
3编写按钮的click事件
procedure TForm1.button1click(sender:Tobject);
begin
//试图转换编辑框架中的金额数值,转换结果显示到标签上
try
 label1.caption:=convert(strtofloat(edit1.text));
esxcept
 showmessage('无效的数据');
end;
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -