1. {*------------------------------------------------
  2. 金额大小写转换函数
  3. @author 王云盼
  4. @version V1506.01
     delphi7测试OK
  5. -------------------------------------------------}
  6. unit UnTranRMB; //主要是考虑数字的小数部分,和大写金额的零
  7.  
  8. interface
  9.  
  10. uses
  11. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  12. Dialogs, StdCtrls;
  13.  
  14. function TranRMB(const Value: string): string; /// const 和 var 常量 变量 数字金额转换成大写金额
  15. function TranNum(M: string):string; /// 大写金额转换成数字金额
  16.  
  17. implementation
  18.  
  19. {*------------------------------------------------
  20. 判断是否有小数点, 切给出小数点出现的位置 和小数点的数目
  21. @param S 字符串
  22. @param Pos 小数点位置
  23. @param Number 小数点个数
  24. @return Boolean
  25. -------------------------------------------------}
  26. function IsPoint(S: string; var Pos: Integer; var Number: integer): Boolean;
  27. var
  28. I: integer;
  29. begin
  30. Result := False;
  31. Number := 0;
  32. for I := 1 to length(S) do
  33. begin
  34. if S[I] = '.' then
  35. begin
  36. Pos := I;
  37. Number := Number + 1;
  38. Result := True;
  39. end;
  40. end;
  41. end;
  42.  
  43. {*------------------------------------------------
  44. 检测字符串是否合理,若小数点超过1个或者字符串开头是0
  45. @param Value
  46. @return Boolean
  47. -------------------------------------------------}
  48. function ChickStr(Value: double): Boolean;
  49. var
  50. J, K : Integer;
  51. begin
  52. Result := False;
  53. if Value <= 0 then
  54. Result := True;
  55. if IsPoint(floatToStr(Value), J, K) = True then
  56. if K >= 2 then
  57. Result := True;
  58. end;
  59.  
  60. {*------------------------------------------------
  61. 转换小写函数
  62. @param
  63. @return
  64. -------------------------------------------------}
  65. function TranNum(M: string):string;
  66. var
  67. N: Integer;
  68. S: string;
  69. begin
  70. S := '.00';
  71. if Length(M) = 1 then
  72. Result := '¥' + M + S
  73. else Result := '¥' + M ;
  74. end;
  75.  
  76. {*------------------------------------------------
  77. 数字金额转换成大写金额
  78. @param
  79. @return
  80. -------------------------------------------------}
  81. function TranRMB(const Value: string): string;
  82. var
  83. I, J, K, L, V, Pos, LZPart, LXPart : integer;
  84. S1: string;
  85. IsZero: Boolean;
  86. begin
  87. if ((Value[1]='0') and (Value[2]<>'.')) or (Value[1]='.') then /// 第一位不能为小数点
  88. begin
  89. ShowMessage('不符合要求');
  90. exit;
  91. end;
  92. //if ChickStr(FloatToStr(S1)) = True then exit; /// 判断是否可以转换
  93. L := length(Value); /// 初始化转换的数字长度
  94. Result := '人民币'; /// 初始化返回值
  95.  
  96. /// 有小数情况
  97. if IsPoint(Value, Pos, J) = True then
  98. begin
  99. LXPart := L - Pos; /// 小数部分长度
  100. LZPart := L - LXPart - 1; /// 整数部分长度
  101. if StrToFloat(Value) = 0 then
  102. begin
  103. Result :=Result + '零元整';
  104. exit;
  105. end;
  106. for J := 1 to LZPart do /// 当前位置
  107. begin
  108. K := StrToInt(Value[J]); /// 当前位置的内容
  109. V := LZPart - J + 1; /// 当前位置的权
  110. case K of /// 获取当前位置内容的大写值
  111. 1: S1 := '壹';
  112. 2: S1 := '贰';
  113. 3: S1 := '叁';
  114. 4: S1 := '肆';
  115. 5: S1 := '伍';
  116. 6: S1 := '陆';
  117. 7: S1 := '柒';
  118. 8: S1 := '捌';
  119. 9: S1 := '玖';
  120. 0: begin /// 有0的情况
  121. S1 := '零';
  122. if J < LZPart then /// 如果不是最后一位,则判断低位是否也有0,有0不显示
  123. begin
  124. if (Value[J+1] = '') or (Value[J+1] = '0') then
  125. S1 := '';
  126. end;
  127. if J = LZPart then /// 0在最后一位也不显示
  128. S1 := '';
  129. end;
  130. end;
  131. case V of /// 权的情况
  132. 1:begin
  133. if K = 0 then
  134. begin
  135. if StrToFloat(Value) < 1 then
  136. begin
  137. S1 := '';
  138. Result := Result + S1;
  139. end
  140. else begin
  141. S1 := '';
  142. Result := Result + S1 + '元' ;
  143. end;
  144. end
  145. else
  146. Result := Result + S1 + '元';
  147. end;
  148. 2:begin
  149. if K = 0 then
  150. Result := Result + S1
  151. else
  152. Result := Result + S1 + '拾';
  153. end;
  154. 3:begin
  155. if K = 0 then
  156. Result := Result + S1
  157. else
  158. Result := Result + S1 + '百' ;
  159. end;
  160. 4:begin
  161. if K = 0 then
  162. Result := Result + S1
  163. else
  164. Result := Result + S1 + '仟' ;
  165. end;
  166. 5:begin
  167. if K = 0 then
  168. begin
  169. S1 := '';
  170. Result := Result + S1 + '万' ;
  171. end
  172. else
  173. Result := Result + S1 + '万';
  174. end;
  175. 6:begin
  176. if K = 0 then
  177. Result := Result + S1
  178. else
  179. Result := Result + S1 + '拾';
  180. end;
  181. 7:begin
  182. if K = 0 then
  183. Result := Result + S1
  184. else
  185. Result := Result + S1 + '百';
  186. end;
  187. 8:begin
  188. if K = 0 then
  189. Result := Result + S1
  190. else
  191. Result := Result + S1 + '仟';
  192. end;
  193. 9:begin
  194. if K = 0 then
  195. begin
  196. S1 := '';
  197. Result := Result + S1 + '万' ;
  198. end
  199. else
  200. Result := Result + S1 + '亿';
  201. end;
  202. 10:begin
  203. if K = 0 then
  204. Result := Result + S1
  205. else
  206. Result := Result + S1 + '拾';
  207. end;
  208. 11:begin
  209. if K = 0 then
  210. Result := Result + S1
  211. else
  212. Result := Result + S1 + '百';
  213. end;
  214. 12:begin
  215. if K = 0 then
  216. Result := Result + S1
  217. else
  218. Result := Result + S1 + '仟';
  219. end;
  220. 13:begin
  221. if K = 0 then
  222. Result := Result + S1
  223. else
  224. Result := Result + S1 + '万';
  225. end;
  226. 14:begin
  227. if K = 0 then
  228. Result := Result + S1
  229. else
  230. Result := Result + S1 + '兆';
  231. end;
  232. end;
  233. end;
  234. for I := 1 to LXPart do
  235. begin
  236. V := StrToInt(Value[I+Pos]) ;
  237. case V of
  238. 1: S1 := '壹';
  239. 2: S1 := '贰';
  240. 3: S1 := '叁';
  241. 4: S1 := '肆';
  242. 5: S1 := '伍';
  243. 6: S1 := '陆';
  244. 7: S1 := '柒';
  245. 8: S1 := '捌';
  246. 9: S1 := '玖';
  247. 0: begin
  248. S1 := '零';
  249. if I < L then /// 如果不是最后一位
  250. begin
  251. if (Value[I+Pos+1] = '') or (Value[I+Pos+1] = '0') then
  252. begin
  253. IsZero := True;
  254. S1 := '';
  255. end;
  256. end;
  257. if I = L then
  258. S1 := '';
  259. end;
  260. end;
  261.  
  262. case I of
  263. 1: begin
  264. if V = 0 then
  265. begin
  266. Result := Result + S1 ;
  267. end
  268. else
  269. Result := Result + S1 + '角';
  270. end;
  271. 2: begin
  272. if V = 0 then
  273. begin
  274. Result := Result + S1 ;
  275. end
  276. else
  277. Result := Result + S1 + '分';
  278. end;
  279. 3: begin
  280. if V = 0 then
  281. begin
  282. Result := Result + S1 ;
  283. end
  284. else
  285. Result := Result + S1 + '厘';
  286. end;
  287. 4: begin
  288. if V = 0 then
  289. begin
  290. Result := Result + S1 ;
  291. end
  292. else
  293. Result := Result + S1 + '毫';
  294. end;
  295. end;
  296. end;
  297. if S1 = '' then Result := Result + '整';
  298. end
  299.  
  300. /// 不是小数情况
  301. else begin
  302. for I := 1 to L do /// 当前位的位置
  303. begin
  304. V := StrToInt(Value[I]) ; /// 当前位的内容
  305. K := L - I + 1; /// 当前位的权
  306. case V of
  307. 1: S1 := '壹';
  308. 2: S1 := '贰';
  309. 3: S1 := '叁';
  310. 4: S1 := '肆';
  311. 5: S1 := '伍';
  312. 6: S1 := '陆';
  313. 7: S1 := '柒';
  314. 8: S1 := '捌';
  315. 9: S1 := '玖';
  316. 0: begin
  317. S1 := '零';
  318. if I < L then /// 如果不是最后一位
  319. begin /// 判断下一位是不是0,低位0不显示
  320. if (Value[i+1] = '') or (Value[i+1] = '0') then
  321. S1 := '';
  322. end;
  323. if I = L then
  324. S1 := '';
  325. end;
  326. end;
  327.  
  328. case K of
  329. 1:begin
  330. if V = 0 then /// 当有零的情况
  331. Result := Result + S1 + '元整'
  332. else
  333. Result := Result + S1 + '元整';
  334. end;
  335. 2:begin
  336. if V = 0 then
  337. Result := Result + S1
  338. else
  339. Result := Result + S1 + '拾';
  340. end;
  341. 3:begin
  342. if V = 0 then
  343. Result := Result + S1
  344. else
  345. Result := Result + S1 + '百' ;
  346. end;
  347. 4:begin
  348. if V = 0 then
  349. Result := Result + S1
  350. else
  351. Result := Result + S1 + '仟' ;
  352. end;
  353. 5:begin
  354. if V = 0 then
  355. begin
  356. S1 := '';
  357. Result := Result + S1 + '万' ;
  358. end
  359. else
  360. Result := Result + S1 + '万';
  361. end;
  362. 6:begin
  363. if V = 0 then
  364. Result := Result + S1
  365. else
  366. Result := Result + S1 + '拾';
  367. end;
  368. 7:begin
  369. if V = 0 then
  370. Result := Result + S1
  371. else
  372. Result := Result + S1 + '百';
  373. end;
  374. 8:begin
  375. if V = 0 then
  376. Result := Result + S1
  377. else
  378. Result := Result + S1 + '仟';
  379. end;
  380. 9:begin
  381. if V = 0 then
  382. begin
  383. S1 := '';
  384. Result := Result + S1 + '亿' ;
  385. end
  386. else
  387. Result := Result + S1 + '亿';
  388. end;
  389. 10:begin
  390. if V = 0 then
  391. Result := Result + S1
  392. else
  393. Result := Result + S1 + '拾';
  394. end;
  395. 11:begin
  396. if V = 0 then
  397. Result := Result + S1
  398. else
  399. Result := Result + S1 + '百';
  400. end;
  401. 12:begin
  402. if V = 0 then
  403. Result := Result + S1
  404. else
  405. Result := Result + S1 + '仟';
  406. end;
  407. 13:begin
  408. if V = 0 then
  409. Result := Result + S1
  410. else
  411. Result := Result + S1 + '万';
  412. end;
  413. 14:begin
  414. if V = 0 then
  415. Result := Result + S1
  416. else
  417. Result := Result + S1 + '兆';
  418. end;
  419. end;
  420. end;
  421. end;
  422. end;
  423.  
  424. 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. LVS+Keepalived搭建

    LVS+Keepalived搭建 原理说明 (推荐): http://www.cnblogs.com/likehua/archive/2014/06/19/3796849.html http://ou ...

  2. 关于OPC自动化接口编程(OPCDAAuto.dll)几点注意问题

    为了能够在工作中方便的应用OPC和充分的理解OPC的开发流程.内部机制,这两天正在研究开发OPC客户端程序,一般我们开发OPC客户端程序有以下几种方式: (1)       使用OPCNetAPI,需 ...

  3. CRC码计算

    循环冗余校验检错方案 上节介绍的奇偶校验码(PCC)只能校验一位错误,本节所要介绍的循环冗余校验码(CRC)的检错能力更强,可以检出多位错误. 1. CRC校验原理 CRC校验原理看起来比较复杂,好难 ...

  4. jmeter 打不开 提示“Not able to find Java executable or version”的解决办法

    Not able to find Java executable or version. Please check your Java installation . errorlevel=2Not a ...

  5. 让memcached分布式

    memcached是应用最广的开源cache产品,它本身不提供分布式的解决方案,我猜想一方面它想尽量保持产品简单高效,另一方面cache的key-value的特性使得让memcached分布式起来比较 ...

  6. profile MySQL性能分析工具

    分析SQL执行带来的开销是优化SQL的重要手段.在MySQL数据库中,可以通过配置profiling参数来启用SQL剖析.该参数可以在全局和session级别来设置.对于全局级别则作用于整个MySQL ...

  7. mysql replication /mysql 主从复制原理

    一下内容均是根据leader的培训分享整理而成 ************************************我是分割线*********************************** ...

  8. 【原创】深入理解Docker容器和镜像 -- 分析了docker的命令含义

    10张图带你深入理解Docker容器和镜像 镜像(Image)就是一堆只读层(read-only layer)的统一视角 要点:容器 = 镜像 + 读写层.并且容器的定义并没有提及是否要运行容器. 一 ...

  9. Perl参考函数/教程

    这是标准的Perl解释器所支持的所有重要函数/功能的列表.在一个函数中找到它的详细信息. 功能丰富的 Perl:轻松调试 Perl Perl脚本的调试方法 perl 入门教程 abs - 绝对值函数 ...

  10. 1060 Are They Equal

    题意: 给出两个浮点数(最大不超过10^100),以及存储的有效位数,判断这两个数是否相等.如12300和12358.9若存储的有效位数为3,则均表示为0.123*10^5,因此视为相等. 思路:[字 ...