{*------------------------------------------------
金额大小写转换函数
@author 王云盼
@version V1506.01
 在delphi7测试OK
-------------------------------------------------}
unit UnTranRMB; //主要是考虑数字的小数部分,和大写金额的零 interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls; function TranRMB(const Value: string): string; /// const 和 var 常量 变量 数字金额转换成大写金额
function TranNum(M: string):string; /// 大写金额转换成数字金额 implementation {*------------------------------------------------
判断是否有小数点, 切给出小数点出现的位置 和小数点的数目
@param S 字符串
@param Pos 小数点位置
@param Number 小数点个数
@return Boolean
-------------------------------------------------}
function IsPoint(S: string; var Pos: Integer; var Number: integer): Boolean;
var
I: integer;
begin
Result := False;
Number := 0;
for I := 1 to length(S) do
begin
if S[I] = '.' then
begin
Pos := I;
Number := Number + 1;
Result := True;
end;
end;
end; {*------------------------------------------------
检测字符串是否合理,若小数点超过1个或者字符串开头是0
@param Value
@return Boolean
-------------------------------------------------}
function ChickStr(Value: double): Boolean;
var
J, K : Integer;
begin
Result := False;
if Value <= 0 then
Result := True;
if IsPoint(floatToStr(Value), J, K) = True then
if K >= 2 then
Result := True;
end; {*------------------------------------------------
转换小写函数
@param
@return
-------------------------------------------------}
function TranNum(M: string):string;
var
N: Integer;
S: string;
begin
S := '.00';
if Length(M) = 1 then
Result := '¥' + M + S
else Result := '¥' + M ;
end; {*------------------------------------------------
数字金额转换成大写金额
@param
@return
-------------------------------------------------}
function TranRMB(const Value: string): string;
var
I, J, K, L, V, Pos, LZPart, LXPart : integer;
S1: string;
IsZero: Boolean;
begin
if ((Value[1]='0') and (Value[2]<>'.')) or (Value[1]='.') then /// 第一位不能为小数点
begin
ShowMessage('不符合要求');
exit;
end;
//if ChickStr(FloatToStr(S1)) = True then exit; /// 判断是否可以转换
L := length(Value); /// 初始化转换的数字长度
Result := '人民币'; /// 初始化返回值 /// 有小数情况
if IsPoint(Value, Pos, J) = True then
begin
LXPart := L - Pos; /// 小数部分长度
LZPart := L - LXPart - 1; /// 整数部分长度
if StrToFloat(Value) = 0 then
begin
Result :=Result + '零元整';
exit;
end;
for J := 1 to LZPart do /// 当前位置
begin
K := StrToInt(Value[J]); /// 当前位置的内容
V := LZPart - J + 1; /// 当前位置的权
case K of /// 获取当前位置内容的大写值
1: S1 := '壹';
2: S1 := '贰';
3: S1 := '叁';
4: S1 := '肆';
5: S1 := '伍';
6: S1 := '陆';
7: S1 := '柒';
8: S1 := '捌';
9: S1 := '玖';
0: begin /// 有0的情况
S1 := '零';
if J < LZPart then /// 如果不是最后一位,则判断低位是否也有0,有0不显示
begin
if (Value[J+1] = '') or (Value[J+1] = '0') then
S1 := '';
end;
if J = LZPart then /// 0在最后一位也不显示
S1 := '';
end;
end;
case V of /// 权的情况
1:begin
if K = 0 then
begin
if StrToFloat(Value) < 1 then
begin
S1 := '';
Result := Result + S1;
end
else begin
S1 := '';
Result := Result + S1 + '元' ;
end;
end
else
Result := Result + S1 + '元';
end;
2:begin
if K = 0 then
Result := Result + S1
else
Result := Result + S1 + '拾';
end;
3:begin
if K = 0 then
Result := Result + S1
else
Result := Result + S1 + '百' ;
end;
4:begin
if K = 0 then
Result := Result + S1
else
Result := Result + S1 + '仟' ;
end;
5:begin
if K = 0 then
begin
S1 := '';
Result := Result + S1 + '万' ;
end
else
Result := Result + S1 + '万';
end;
6:begin
if K = 0 then
Result := Result + S1
else
Result := Result + S1 + '拾';
end;
7:begin
if K = 0 then
Result := Result + S1
else
Result := Result + S1 + '百';
end;
8:begin
if K = 0 then
Result := Result + S1
else
Result := Result + S1 + '仟';
end;
9:begin
if K = 0 then
begin
S1 := '';
Result := Result + S1 + '万' ;
end
else
Result := Result + S1 + '亿';
end;
10:begin
if K = 0 then
Result := Result + S1
else
Result := Result + S1 + '拾';
end;
11:begin
if K = 0 then
Result := Result + S1
else
Result := Result + S1 + '百';
end;
12:begin
if K = 0 then
Result := Result + S1
else
Result := Result + S1 + '仟';
end;
13:begin
if K = 0 then
Result := Result + S1
else
Result := Result + S1 + '万';
end;
14:begin
if K = 0 then
Result := Result + S1
else
Result := Result + S1 + '兆';
end;
end;
end;
for I := 1 to LXPart do
begin
V := StrToInt(Value[I+Pos]) ;
case V of
1: S1 := '壹';
2: S1 := '贰';
3: S1 := '叁';
4: S1 := '肆';
5: S1 := '伍';
6: S1 := '陆';
7: S1 := '柒';
8: S1 := '捌';
9: S1 := '玖';
0: begin
S1 := '零';
if I < L then /// 如果不是最后一位
begin
if (Value[I+Pos+1] = '') or (Value[I+Pos+1] = '0') then
begin
IsZero := True;
S1 := '';
end;
end;
if I = L then
S1 := '';
end;
end; case I of
1: begin
if V = 0 then
begin
Result := Result + S1 ;
end
else
Result := Result + S1 + '角';
end;
2: begin
if V = 0 then
begin
Result := Result + S1 ;
end
else
Result := Result + S1 + '分';
end;
3: begin
if V = 0 then
begin
Result := Result + S1 ;
end
else
Result := Result + S1 + '厘';
end;
4: begin
if V = 0 then
begin
Result := Result + S1 ;
end
else
Result := Result + S1 + '毫';
end;
end;
end;
if S1 = '' then Result := Result + '整';
end /// 不是小数情况
else begin
for I := 1 to L do /// 当前位的位置
begin
V := StrToInt(Value[I]) ; /// 当前位的内容
K := L - I + 1; /// 当前位的权
case V of
1: S1 := '壹';
2: S1 := '贰';
3: S1 := '叁';
4: S1 := '肆';
5: S1 := '伍';
6: S1 := '陆';
7: S1 := '柒';
8: S1 := '捌';
9: S1 := '玖';
0: begin
S1 := '零';
if I < L then /// 如果不是最后一位
begin /// 判断下一位是不是0,低位0不显示
if (Value[i+1] = '') or (Value[i+1] = '0') then
S1 := '';
end;
if I = L then
S1 := '';
end;
end; case K of
1:begin
if V = 0 then /// 当有零的情况
Result := Result + S1 + '元整'
else
Result := Result + S1 + '元整';
end;
2:begin
if V = 0 then
Result := Result + S1
else
Result := Result + S1 + '拾';
end;
3:begin
if V = 0 then
Result := Result + S1
else
Result := Result + S1 + '百' ;
end;
4:begin
if V = 0 then
Result := Result + S1
else
Result := Result + S1 + '仟' ;
end;
5:begin
if V = 0 then
begin
S1 := '';
Result := Result + S1 + '万' ;
end
else
Result := Result + S1 + '万';
end;
6:begin
if V = 0 then
Result := Result + S1
else
Result := Result + S1 + '拾';
end;
7:begin
if V = 0 then
Result := Result + S1
else
Result := Result + S1 + '百';
end;
8:begin
if V = 0 then
Result := Result + S1
else
Result := Result + S1 + '仟';
end;
9:begin
if V = 0 then
begin
S1 := '';
Result := Result + S1 + '亿' ;
end
else
Result := Result + S1 + '亿';
end;
10:begin
if V = 0 then
Result := Result + S1
else
Result := Result + S1 + '拾';
end;
11:begin
if V = 0 then
Result := Result + S1
else
Result := Result + S1 + '百';
end;
12:begin
if V = 0 then
Result := Result + S1
else
Result := Result + S1 + '仟';
end;
13:begin
if V = 0 then
Result := Result + S1
else
Result := Result + S1 + '万';
end;
14:begin
if V = 0 then
Result := Result + S1
else
Result := Result + S1 + '兆';
end;
end;
end;
end;
end; end.

delphi 金额大小写转换函数的更多相关文章

  1. Oracle 大小写转换函数

    Oracle 大小写转换函数 转大写UPPER 转小写LOWER 测试: select UPPER('Test') as u from dual; select LOWER('Test') as l ...

  2. 【Python-2.7】大小写转换函数

    字母大小写是编程过程中经常遇到的问题,如下函数可以灵活的进行大小写转换: title():把单词首字母转换为大写: upper():把每个字母转换为大写: lower():把每个字母转换为小写. 示例 ...

  3. .NET下金额大小写转换

    说明:金额转换可以转换50位的数值,单位从分到级.对于中间部分是否显示零,可以根据修改TranslateJInen()函数修改.中间数值为零的去掉不显示 public string GetChCapi ...

  4. double四舍五入,商品金额大小写转换,设置货币的小数位数跟格式输出,进制转化

      1:计算double值四舍五入的方法 对小数数值进行四舍五入,首先应该确认保留小数位, 如果数值的小数精度大于保留小数位,那么开始四舍五入计算.四舍五入的方法非常简单,在所有要丢失精度的小数位中加 ...

  5. python大小写转换函数

    1.全部转换成大写:upper() 用法: str = 'marsggbo'     print str.upper() 结果:MARSGGBO 2.全部转换成小写:lower() 用法:str = ...

  6. php大小写转换函数

    1.将字符串转换成小写   strtolower(): 该函数将传入的字符串参数所有的字符都转换成小写,并以小定形式放回这个字 符串.例: <?php $str = "I want T ...

  7. strtolower() strtoupper()等字符串大小写转换函数

    $str = "Mary Had A Little Lamb and She LOVED It So"; string strtolower ( string $str )— 将字 ...

  8. php中常用的字符串大小写转换函数实例解释

    PHP字符串处理函数中,最为简单的几个函数,相关解释就不上了,直接看例子. PHP字符串处理函数中,最为简单的几个函数,相关解释就不上了,直接看例子. strtolower函数.strtoupper函 ...

  9. jQuery字母大小写转换函数

    toLowerCase() ------ 将字符串中的所有字符都转换成小写: toUpperCase() ------ 将字符串中的所有字符都转换成大写:

随机推荐

  1. sourcetree 分支的创建合并

    sourcetree 分支的创建合并,提交 https://blog.csdn.net/qq_34975710/article/details/74469068 sourcetree测试版本的配置忽略 ...

  2. erlang使用心跳模式启动shell

    资料http://blog.yufeng.info/archives/2832 借鉴自从http://blog.csdn.net/mycwq/article/details/18306753 测试例子 ...

  3. nginx.conf解读

    通常我们需要配置nginx.conf或者配置子项目的配置文件,那么我们需要解读它里面每一个参数的意义,就来个范例解读吧(有中午注释) #运行用户 user www-data; #启动进程,通常设置成和 ...

  4. 1096 Consecutive Factors

    题意: 给出一个正整数N,找到最长的连续的可分解因子.如N=630,可被分解为630=3*5*6*7,其中5*6*7是3个连续的因子. 思路: 首先,需要明确,对于任何一个整数,如果它是素数,则不可被 ...

  5. 转: SQL中的where条件,在数据库中提取与应用浅析

    SQL中的where条件,在数据库中提取与应用浅析 http://hedengcheng.com/?p=577 1问题描述 一条SQL,在数据库中是如何执行的呢?相信很多人都会对这个问题比较感兴趣.当 ...

  6. python实现文件加密

    前言: 想实现批量文件加密,可惜批量.展时没有思路 0x1 没有加密前的图片 加密后!!! !!!打不开了 0x02: 代码 import hashlib def get_sha1(f): xd=op ...

  7. K12协同开发在做常见问题时候遇到的问题

    一.在做常见问题的时候遇到的问题 在后端处理数据的时候是通过serialize来实现的,从数据库中查出自己想要的数据,直接返回数据. 在前端发送ajax请求获取数据并且在页面上以好看的形式渲染. 1. ...

  8. 提高ListView的效率

    按照普通的写法,如果ListView里面有比较多的东西的话,在加载每一个Item的时候,是非常非常卡的.具体表现就是滚动起来的时候会看见明显的卡顿. 关键还是处理自定义Adapter里面的getVie ...

  9. pl/sql Command Window

    由于工作需要,最近需要执行sql脚本,之前一直在用执行按钮操作,但最近公司制定了一套标准,其中就有执行sql脚本规范: 以前执行存存储过程: 现在修改存储过程如下: 第一步,打开对应窗口: 第二步,输 ...

  10. coprime Sequence

    Do you know what is called ``Coprime Sequence''? That is a sequence consists of nn positive integers ...