数字转换大写人民币的delphi实现
function TForm1.changeRmb(const strRmb:string):string;
var
txt,strhighlevel:string;
i,n,m,ilen,ipos:Integer; //n记录整数部分长度,m记录分数部分长度
strarray,strlevel:array of string;
p:pchar;
ispoint:boolean;//判断是否有小数点
begin
ispoint:=false;
result:='';
ipos:=0;
m:=0;
txt:=Trim(strRmb);
i:=1;
p:=PChar(txt);
//去除开头的0,以及.
if ((txt[1]='0') and (txt[2]<>'.')) or (txt[1]='.') then
begin
ShowMessage('第1位不能为0或者是.,退出操作');
exit;
end;
//检查字符的合法性
while (i<length(txt))do
begin
if (p^>'9') or ((p^<'0') and (P^<>'.')) then //ord('.')=46
begin
ShowMessage(PChar('第'+inttostr(i)+'位包含非数字字符,将退出操作'));
Exit;
end;
if P^='.' then
if ispoint then
begin
showmessage('太多小数点,将退出!');
exit;
end
else
begin
ipos:=i;
ispoint:=true;
end;
Inc(p);
Inc(i);
end;//while
ilen:=Length(txt);
if ispoint then
begin
n:=ipos-1;
m:=ilen-ipos;
end
else
n:=ilen;
//判断是否超过万,或亿
if m>3 then
begin
ShowMessage('小数点后位数超过3,无法转换!');
Exit;
end;
SetLength(strarray,ilen+8);
SetLength(strlevel,ilen+8); for i:=iLen downto 1 do
begin
if txt[i]<>'.' then
case strtoint(txt[i]) of
1:strarray[i]:='壹';
2:strarray[i]:='贰';
3:strarray[i]:='叁';
4:strarray[i]:='肆';
5:strarray[i]:='伍';
6:strarray[i]:='陆';
7:strarray[i]:='柒';
8:strarray[i]:='捌';
9:strarray[i]:='玖';
0:
begin
strarray[i]:='零';
if i<ilen then //如果低位也为零,低位零不显示
if (strarray[i+1]= '') or (strarray[i+1]= '零') then
begin
//strarray[i+1]:= '';
strarray[i]:= '';
end;
if i=n then strarray[i]:='';
strlevel[i]:='';
end;
end; //case
end;
//先处理 小数点部分 if m>0 then
begin
for i:=m downto 1 do
begin
strlevel[ipos+i]:='';
case i-1 of
0:
if txt[ipos+i]='0' then
strarray[ipos+i]:=''
else
strlevel[ipos+i]:='角';
1:
if txt[ipos+i]='0' then
strarray[ipos+i]:=''
else
strlevel[ipos+i]:='分';
2:
if txt[ipos+i]='0' then
strarray[ipos+i]:=''
else strlevel[ipos+i]:='厘';
end;
Result:=strarray[ipos+i]+strlevel[ipos+i]+result;
end;
end;
if ispoint and (txt[ipos-1]='0') and (n=1) then
Result:=result+'' //如果少于1块时,不要显示元。
else
Result:='元'+result; for i:=n downto 1 do
begin case n-i of
0,4,8,12: strlevel[i]:='';
1,5,9,13: strlevel[i]:='拾';
2,6,10,14: strlevel[i]:='佰';
3,7,11,15: strlevel[i]:='仟';
end; //case
if (txt[i]='0') then strlevel[i]:='';
//要处理零 以及加上万、亿
if n-i=4 then
begin
if strarray[i]='零' then strarray[i]:='';
Result:=strarray[i]+strlevel[i]+'万'+result
end
else if n-i=8 then
begin
if strarray[i]='零' then strarray[i]:='';
Result:=strarray[i]+strlevel[i]+'亿'+result
end //begin
else if n-i=12 then
begin
if strarray[i]='零' then strarray[i]:='';
Result:=strarray[i]+strlevel[i]+'兆'+result
end //begin
else
Result:=strarray[i]+strlevel[i]+result;
end; //for
end;
数字转换大写人民币的delphi实现的更多相关文章
- 算法--java实现将数字转换成人民币大写(迅雷面试题)
今天去迅雷面试,是个数字转换成人民币的算法题: public class Rmb { /** * 人民币的基本信息和操作 * * @author soyoungboy * @version 1.0 * ...
- js 将数字转换成人民币大写的方法
//将数字转换成人民币大写的方法 var digitUppercase = function (n) { var fraction = ['角', '分']; var digit = [ '零', ' ...
- java 金额数字转换大写算法
根据人民币大写金额规范,转换有几点要注意的: 阿拉伯数字中间有"0"时,中文大写金额中间可以只写一个"零"字.如¥1,409.50,应写成人民币壹仟肆佰零玖圆伍 ...
- C#小写数字金额转换成大写人民币金额的算法
C#小写数字金额转换成大写人民币金额的算法 第一种方法: using System.Text.RegularExpressions;//首先引入命名空间 private string DaXie(st ...
- ORACLE数字转换人民币大写
ORACLE 数字转换人民币大写 示例. 数字 :183066999230.68 人民币大写 :壹仟捌佰参拾亿陆仟陆佰玖拾玖万玖仟贰佰参 ...
- C# 数字转换成大写
/// <summary> /// 数字转大写 /// </summary> /// <param name="Num">数字</para ...
- C# 数字转换成汉字大写 数值转换成汉字大写
1.数字转换成汉字大写 public string NumToChinese(string x) { //数字转换为中文后的数组 //转载请注明来自 http://www.shang11.com st ...
- js 将数字转换成中文大写
//完成将 toChineseNum, 可以将数字转换成中文大写的表示,处理到万级别,例如 toChineseNum(12345),返回 一万二千三百四十五. const toChinesNum = ...
- PHP 数字转大写
<?php header("content-type:text/html;charset=utf-8"); function numToRmb($num){ $rmbNum ...
随机推荐
- IntellIJ IDEA 配置 Vue 支持
IDEA版本: IntelliJ IDEA 2017.2Build #IU-172.3317.76, built on July 15, 2017Licensed to Administrator J ...
- java.security.ProviderException: java.security.KeyException
本机部署没问题,部署到linux服务器报错: javax.net.ssl.SSLException: java.security.ProviderException: java.security.Ke ...
- 5. RAMN备份与恢复
一. rman简介 RMAN(Recovery Manager)是一种用于备份(backup).还原(restore)和恢复(recover)数据库的 Oracle 工具.RMAN只能用于ORACLE ...
- [Ubuntu] LightDM 轻量级桌面显示管理器
LightDM(Light Display Manager)是一个全新的轻量级 Linux 桌面显示管理器,而传统的 Ubuntu 是使用 GNOME 桌面标准的 GDM. LightDM 是一个跨桌 ...
- OpenGL——折线图柱状图饼图绘制
折线图绘制代码: #include<iostream> //旧版本 固定管线 #include<Windows.h> #include <GL/glut.h> // ...
- Linux设备驱动剖析之Input(二)
分别是总线类型.厂商号.产品号和版本号. 1156行,evbit,设备支持的事件类型的位图,每一位代表一种事件,比如EV_KEY.EV_REL事件等等.BITS_TO_LONGS(nr)是一个宏,假设 ...
- QT 获取电脑时间
使用环境: VS2010 & QT Designer5 #include <QDateTime> //包含头文件 QDateTime local(QDateTime::curre ...
- js---手机端滑动进度条
最近做项目,有一个滑动音乐播放进度条的效果,但是使用input的 range 来做会出现一些问题,想了想还是用JS来写.直接上代码: <!doctype html> <html la ...
- shell特殊变量,记录一下
$0 当前脚本的文件名 $n 传递给脚本或函数的参数.n 是一个数字,表示第几个参数.例如,第一个参数是$1,第二个参数是$2. $# 传递给脚本或函数的参数个数. $* 传递给脚本或函数的所有参数. ...
- 启动elk中elasticsearch服务报错which: no java in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
解决办法: vi /etc/sysconfig/elasticsearch JAVA_HOME=/usr/local/java sudo systemctl restart elasticsearch ...