批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程
[批处理文件精品]批处理版照片整理器[批处理文件精品]纯批处理备份&还原驱动在线第三方下载
返回列表 发帖

[数值计算] 求批处理人民币小写转大写的算法

今天突然想到用批处理做一个人民币小写金额转大写金额的批处理,于是着手去写,谁料写到一半发现思路不对。
主要体现在一个数中连续零的问题没法解决。
于是百度了下别人写的代码,发现也不行。
比如:100000008.00
在此求高手支招!最好奉上代码,有劳!

我原本的思路是:先把金额数字转换为大写,然后补上单位,最后解决关于连续零的问题(无奈发现连续零不好解决)

【扫描二维码捐助论坛的朋友请留言注明论坛账号】http://bbs.bathome.net/thread-10403-1-1.html
【批处理在线视频分享】http://bbs.bathome.net/thread-31727-1-1.html
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html

TOP

回复 2# Batcher


    之前在咱们论坛搜索竟然搜不到,多谢了!

TOP

回复 2# Batcher
先谢谢管理员,我也正需要这样的批处理。
求修改
1、从粘贴板获取金额,运行后,再输出大写金额到粘贴板。
2、能识别千分符。
谢谢了。
  1. :: 人民币大小写互转程序 R3
  2. :: qzwqzw http://bbs.cn-dos.net
  3. :: 2007-01-03 11:15
  4. :: 出处:http://www.cn-dos.net/forum/viewthread.php?tid=26288
  5. @echo off
  6. setlocal EnableDelayedExpansion
  7. for /l %%i in (1,1,100) do (
  8.     set /a numin=!random!*50001-50000000
  9.     set numin=!numin:~0,-2!.!numin:~-2!
  10.     set in=!numin!
  11.     call :Num2RMB
  12.     set in=!out!
  13.     call :RMB2Num
  14.     echo.%%i [!numin!:!in!:!out!]
  15.     if !numin! neq !out! set /p=--- Invalid ---
  16.     set out=
  17. )
  18. if "%~0"=="%~f0" pause
  19. endlocal
  20. goto :eof
  21. :Num2RMB
  22. setlocal
  23. set num=%in%
  24. set num=0%num%
  25. for /f "tokens=1,2,* delims=." %%f in ("%num%") do (
  26.     set num2=%%g00
  27.     set num=%%f!num2:~0,2!
  28.     if not "%%h"=="" goto :eof
  29. )
  30. :del_pre0
  31. if "%num:~0,1%"=="0" (
  32.     set num=%num:~1%
  33.     goto del_pre0
  34. )
  35. :checknum
  36. set num=%num:,=%
  37. set /a num2=num+0
  38. if not "%num%"=="%num2%" goto :eof
  39. if %num% geq 1000000000000 goto :eof
  40. if %num% leq 0 goto :eof
  41. set tbl1=零壹贰叁肆伍陆柒捌玖
  42. set tbl2=分角元拾佰仟万拾佰仟亿拾佰仟
  43. :n2r_loop
  44. call set rmb=%%tbl1:~%num:~-1,1%,1%%%%tbl2:~%bit%,1%%%rmb%
  45. set /a bit+=1
  46. set num=%num:~0,-1%
  47. if not "%num%"=="" goto n2r_loop
  48. set rmb=%rmb:零拾=零%
  49. set rmb=%rmb:零佰=零%
  50. set rmb=%rmb:零仟=零%
  51. set rmb=%rmb:零零=零%
  52. set rmb=%rmb:零零=零%
  53. set rmb=%rmb:零元=元零%
  54. set rmb=%rmb:零万=万零%
  55. set rmb=%rmb:零亿=亿零%
  56. set rmb=%rmb:零零=零%
  57. set rmb=%rmb:零分=零%
  58. set rmb=%rmb:零角=零%
  59. set rmb=%rmb:角零=角%
  60. set rmb=%rmb:零零=整%
  61. endlocal & set out=%rmb%
  62. goto :eof
  63. ::Num2RMB
  64. :RMB2Num
  65. setlocal
  66. set rmb=%in%
  67. set rmb=%rmb:零=%
  68. set rmb=%rmb:整=%
  69. set tbl1=零壹贰叁肆伍陆柒捌玖
  70. set tbl2=分角元拾佰仟万拾佰仟亿拾佰仟
  71. for /l %%i in (1,1,9) do call set rmb%%tbl1:~%%i,1%%=%%i
  72. :r2n_loop
  73. if "%tbl2:~0,1%"=="%rmb:~-1,1%" (
  74.     set rmb=!rmb:~0,-1!
  75.     call set tmp=%%rmb!rmb:~-1,1!%%
  76.     if not "!tmp!"=="" (
  77.         set num=!tmp!!num!
  78.         set rmb=!rmb:~0,-1!
  79.     ) else (
  80.         set num=0!num!
  81.     )
  82. ) else (
  83.     set num=0!num!
  84. )
  85. set tbl2=%tbl2:~1%
  86. if not "%rmb%"=="" if not "%tbl2%"=="" goto r2n_loop
  87. set num=%num:~0,-2%.%num:~-2%
  88. endlocal & set out=%num%
  89. goto :eof
  90. ::RMB2Num
复制代码

TOP

回复 4# lxf0356


    clip 命令可以操作剪贴板,你试试看。
【扫描二维码捐助论坛的朋友请留言注明论坛账号】http://bbs.bathome.net/thread-10403-1-1.html
【批处理在线视频分享】http://bbs.bathome.net/thread-31727-1-1.html
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html

TOP

本帖最后由 smss 于 2019-4-20 18:17 编辑

上至千极下至小数点后12位 范围0~9999999999999999999999999999999999999999999999999999.999999999999
2019.4.20修复已知BUG
  1. @echo off&setlocal enabledelayedexpansion
  2. set unit=仟佰拾极仟佰拾载仟佰拾正仟佰拾涧仟佰拾沟仟佰拾穰仟佰拾秭仟佰拾垓仟佰拾京仟佰拾兆仟佰拾亿仟佰拾万仟佰拾元
  3. set "Z=9999999999999999999999999999999999999999999999999999.999999999999"
  4. :X
  5. color 0d
  6. set /p Z=请输入数字:
  7. if /i "%Z%"=="q" exit
  8. if "%Z%"=="0" echo 零元整&goto X
  9. for /f "tokens=1,2delims=." %%i in ('echo;%Z%^|findstr /b /e "[1-9][0-9]* 0 [1-9][0-9]*\.[0-9]* 0\.[0-9]*"') do (set "a=%%i"&set "b=%%j")
  10. if defined a (if defined b (if "%b:~12%" NEQ "" (goto U) else if "%a:~52%" NEQ "" (goto U) else (goto Y)
  11. ) else if "%a:~52%" NEQ "" (goto U) else (goto Y)) else (goto U)
  12. goto X
  13. :Y
  14. set Y=
  15. for /f "tokens=1,2 delims=." %%a in ("%Z%") do set "Z=%%a"&set "frac=%%b"
  16. if defined frac (set frac=!frac:~0,12!&set m=!frac:~0,1!&if !m! gtr 0 set Y=!m!角
  17. set m=!frac:~1,1!&if !m! gtr 0 set Y=!Y!!m!分
  18. set m=!frac:~2,1!&if !m! gtr 0 set Y=!Y!!m!厘
  19. set m=!frac:~3,1!&if !m! gtr 0 set Y=!Y!!m!毫
  20. set m=!frac:~4,1!&if !m! gtr 0 set Y=!Y!!m!丝
  21. set m=!frac:~5,1!&if !m! gtr 0 set Y=!Y!!m!忽
  22. set m=!frac:~6,1!&if !m! gtr 0 set Y=!Y!!m!微
  23. set m=!frac:~7,1!&if !m! gtr 0 set Y=!Y!!m!纤
  24. set m=!frac:~8,1!&if !m! gtr 0 set Y=!Y!!m!沙
  25. set m=!frac:~9,1!&if !m! gtr 0 set Y=!Y!!m!尘
  26. set m=!frac:~10,1!&if !m! gtr 0 set Y=!Y!!m!埃
  27. set m=!frac:~11,1!&if !m! gtr 0 set Y=!Y!!m!渺)
  28. set n=0
  29. for /l %%a in (0,1,100) do if not "!Z:~%%a,1!"=="" set /a n+=1
  30. if not %Z% equ 0 (for /l %%a in (1,1,%n%) do (set bit=!Z:~-%%a,1!&if not "bit"=="" (set m=!unit:~-%%a,1!&set "Y=!bit!!m!!Y!"
  31. )))
  32. set Y=%Y:0=零%
  33. set Y=%Y:1=壹%
  34. set Y=%Y:2=贰%
  35. set Y=%Y:3=叁%
  36. set Y=%Y:4=肆%
  37. set Y=%Y:5=伍%
  38. set Y=%Y:6=陆%
  39. set Y=%Y:7=柒%
  40. set Y=%Y:8=捌%
  41. set Y=%Y:9=玖%
  42. set Y=%Y:零仟=零%
  43. set Y=%Y:零佰=零%
  44. set Y=%Y:零拾=零%
  45. set Y=%Y:零零零=零%
  46. set Y=%Y:零零=零%
  47. set Y=%Y:零极=极%
  48. set Y=%Y:零载=载%
  49. set Y=%Y:零正=正%
  50. set Y=%Y:零涧=涧%
  51. set Y=%Y:零沟=沟%
  52. set Y=%Y:零穰=穰%
  53. set Y=%Y:零秭=秭%
  54. set Y=%Y:零垓=垓%
  55. set Y=%Y:零京=京%
  56. set Y=%Y:零兆=兆%
  57. set Y=%Y:零亿=亿%
  58. set Y=%Y:零万=万%
  59. set Y=%Y:零元=元%
  60. set Y=%Y:零壹=壹%
  61. set Y=%Y:零贰=贰%
  62. set Y=%Y:零叁=叁%
  63. set Y=%Y:零肆=肆%
  64. set Y=%Y:零伍=伍%
  65. set Y=%Y:零柒=柒%
  66. set Y=%Y:零捌=捌%
  67. set Y=%Y:零玖=玖%
  68. set Y=%Y:极载正涧沟穰秭垓京兆亿万=极%
  69. set Y=%Y:载正涧沟穰秭垓京兆亿万=载%
  70. set Y=%Y:正涧沟穰秭垓京兆亿万=正%
  71. set Y=%Y:涧沟穰秭垓京兆亿万=涧%
  72. set Y=%Y:沟穰秭垓京兆亿万=沟%
  73. set Y=%Y:穰秭垓京兆亿万=穰%
  74. set Y=%Y:秭垓京兆亿万=秭%
  75. set Y=%Y:垓京兆亿万=垓%
  76. set Y=%Y:京兆亿万=京%
  77. set Y=%Y:兆亿万=兆%
  78. set Y=%Y:极载=极%
  79. set Y=%Y:载正=载%
  80. set Y=%Y:正涧=正%
  81. set Y=%Y:涧沟=涧%
  82. set Y=%Y:正涧=正%
  83. set Y=%Y:沟穰=沟%
  84. set Y=%Y:穰秭=穰%
  85. set Y=%Y:秭垓=秭%
  86. set Y=%Y:垓京=垓%
  87. set Y=%Y:京兆=京%
  88. set Y=%Y:兆亿=兆%
  89. set Y=%Y:亿万=亿%
  90. set Y=%Y:穰垓=穰%
  91. set Y=%Y:载正涧沟穰秭垓京兆亿=%
  92. set Y=%Y:载正涧沟穰秭垓京兆=%
  93. set Y=%Y:载正涧沟穰秭垓京=%
  94. set Y=%Y:载正涧沟穰秭垓=%
  95. set Y=%Y:载正涧沟穰秭=%
  96. set Y=%Y:载正涧沟穰=%
  97. set Y=%Y:载正涧沟穰=%
  98. set Y=%Y:载正涧沟=%
  99. set Y=%Y:载正涧=%
  100. set Y=%Y:正涧沟穰秭垓京兆亿=%
  101. set Y=%Y:涧沟穰秭垓京兆亿=%
  102. set Y=%Y:沟穰秭垓京兆亿=%
  103. set Y=%Y:穰秭垓京兆亿=%
  104. set Y=%Y:秭垓京兆亿=%
  105. set Y=%Y:垓京兆亿=%
  106. set Y=%Y:京兆亿=%
  107. set Y=%Y:正沟秭京亿=%
  108. set Y=%Y:正沟秭京=%
  109. set Y=%Y:正沟秭=%
  110. set Y=%Y:正沟=%
  111. color 0b
  112. if !frac! equ 0 (echo %Y%整) else echo %Y%
  113. ping 0 -n "2">nul&goto X
  114. :U
  115. echo 已超出范围,请重新输入&goto X
复制代码
2

评分人数

TOP

不可说不可说
综合型编程论坛
Writing Code That Nobody Else Can Read.

TOP

本帖最后由 smss 于 2019-4-21 11:42 编辑

迷你版
  1. @echo off&setlocal EnableDelayedExpansion
  2. set a=零壹贰叁肆伍陆柒捌玖
  3. set b=分角元拾佰仟万拾佰仟亿拾佰仟
  4. set "Z=999999999999.99"
  5. :X
  6. color 0d
  7. setlocal
  8. ::对输入数字处理,取出整数和小数
  9. set /p Z=请输入金额:
  10. if /i "%Z%"=="q" exit
  11. if "%Z%"=="0" echo 零元整&goto X
  12. for /f "tokens=1,2 delims=." %%a in ('echo;%Z%^|findstr /b /e "[1-9][0-9]* 0 [1-9][0-9]*\.[0-9]* 0\.[0-9]*"') do (set Z2=%%b00&set Z=%%a!Z2:~0,2!&set "i=%%a"&set "j=%%b")
  13. if defined i (if defined j (if "%j:~2%" NEQ "" (goto U) else if "%i:~12%" NEQ "" (goto U) else (goto Y)
  14. ) else if "%i:~12%" NEQ "" (goto U) else (goto Y)) else (goto U)
  15. :Y
  16. call set Y=%%a:~%Z:~-1,1%,1%%%%b:~%bit%,1%%%Y%
  17. set /a bit+=1
  18. set Z=%Z:~0,-1%
  19. if not "%Z%"=="" goto Y
  20. set Y=%Y:零壹=壹%
  21. set Y=%Y:零贰=贰%
  22. set Y=%Y:零叁=叁%
  23. set Y=%Y:零肆=肆%
  24. set Y=%Y:零伍=伍%
  25. set Y=%Y:零柒=柒%
  26. set Y=%Y:零捌=捌%
  27. set Y=%Y:零玖=玖%
  28. set Y=%Y:零仟=零%
  29. set Y=%Y:零佰=零%
  30. set Y=%Y:零拾=零%
  31. set Y=%Y:零零零=零%
  32. set Y=%Y:零零=零%
  33. set Y=%Y:零万=万元%
  34. set Y=%Y:零亿=亿元%
  35. set Y=%Y:零零=零%
  36. set Y=%Y:零分=零%
  37. set Y=%Y:零角=零%
  38. set Y=%Y:角零=角%
  39. set Y=%Y:零零=%
  40. set Y=%Y:零亿=亿%
  41. set Y=%Y:零万=万%
  42. set Y=%Y:零元=%
  43. set Y=%Y:零万=元%
  44. set Y=%Y:亿万=亿%
  45. color 0b
  46. if !j! equ 0 (echo %Y%整) else echo %Y%
  47. endlocal
  48. ping 0 -n "2">nul&goto X
  49. :U
  50. echo 已超出范围,请重新输入&goto X
复制代码

TOP

回复 8# smss


    求修改
1、从粘贴板获取金额,运行后,再输出大写金额到粘贴板。
2、能识别千分符。

TOP

回复  smss


    求修改
1、从粘贴板获取金额,运行后,再输出大写金额到粘贴板。
2、能识别千分符。 ...
lxf0356 发表于 2019-4-21 00:05




http://bbs.bathome.net/thread-8329-1-1.html

TOP

本帖最后由 lxf0356 于 2019-4-29 15:12 编辑
迷你版
smss 发表于 2019-4-19 15:30

借用你的代码,修改了一下,搞定了

TOP

返回列表