|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
『楼 主』:
[共同参与][挑战思路]批处理实现数字金额转大写
使用 LLM 解释/回答一下
看到坛子里越来越多关于挑战批处理算法的讨论,也涌现出一批热衷于挖掘批处理潜能的兄弟,一些批处理不太适合的工作,也渐由批处理来完成,我很是高兴。
现拟一题目--数字金额转大写,这个议题在网上几乎可以找到任何流行语言的版本,唯独缺少批处理版的,这个问题当然不能指望老外来做,然后我们再借鉴 ^_^。
规则如下:
1、接收一串金额数字,转为大写,可能出现的合理格式
为 5821564130 或 5821564.130 或 5,821,564.130 等,
不会出现格式为 58.215.64.130 等小数位不明的数字或其他非金额数字字符。
2、最大位到千亿即可,最小位到分其后忽略。
3、CMD下纯批处理完成,不使用第三方工具。
4、具体转换依据见附录。
附录:
正确填写票据和结算凭证的基本规定
银行、单位和个人填写的各种票据和结算凭证是办理支付结算和现金收付的重要依据,直接关系到支付结算的准确、及时和安全。票据和结算凭证是银行、单位和个人凭以记载帐务的会计凭证,是记载经济业务和明确经济责任的一种书面证书。因此,填写票据和结算凭证,必须做到标准化、规范化,要要素齐全、数字正确、字迹清晰、不错漏、不潦草,防止涂改。
一、中文大写金额数字应用正楷或行书填写,如壹(壹)、贰(貳)、叁(參)、肆(肆)、伍(伍)、陆(陸)、柒、捌、玖、拾、佰、仟、万(萬)、亿、元、角、分、零、整(正)等字样。不得用一、二(两)、三、四、五、六、七、八、九、十、念、毛、另(或0)填写,不得自造简化字。如果金额数字书写中使用繁体字,如贰、陆、亿、万、圆的,也应受理。
二、中文大写金额数字到“元”为止的,在“元”之后,应写“整”(或“正”)字,在“角”之后可以不写“整”(或“正”)字。大写金额数字有“分”的,“分”后面不写“整”(或“正”)字。
三、中文大写金额数字前应标明“人民币”字样,大写金额数字有“分”的,“分”后面不写“整”(或“正”)字。
四、中文大写金额数字前应标明“人民币”字样,大写金额数字应紧接“人民币”字样填写,不得留有空白。大写金额数字前未印“人民币”字样的,应加填“人民币”三字。在票据和结算凭证大写金额栏内不得预印固定的“仟、佰、拾、万、仟、佰、拾、元、角、分”字样。
五、阿拉伯小写金额数字中有“0”时,中文大写应按照汉语语言规律、金额数字构成和防止涂改的要求进行书写。举例如下:
(一)阿拉伯数字中间有“0”时,中文大写金额要写“零”字。如¥1,409.50,应写成人民币壹仟肆佰零玖元伍角。
(二)阿位伯数字中间连续几个“0”时,中文大写金额中间可以只写一个“零”字。如¥6,007.14,应写成人民币陆仟零柒元壹角肆分。
(三)阿拉伯金额数字万位或元位是“0”,或者数字中间连续有几个“0”,万位、元位也是“0”,但千位、角位不是“0”时,中文大写金额中可以只写一个零字,也可以不写“零”字。如¥1,680.32,应写成人民币壹仟陆佰捌拾元零叁角贰分,或者写成人民币壹仟陆佰捌拾元叁角贰分;又如¥107,000.53,应写成人民币壹拾万柒仟元零伍角叁分,或者写成人民币壹拾万零柒仟元伍角叁分。
(四)阿拉伯金额数字角位是“0”,而分位不是“0”时,中文大写金额“元”后面应写“零”字。如¥16,409.02,应写成人民币壹万陆仟肆佰零玖元零贰分;又如¥325.04,应写成人民币叁佰贰拾伍元零肆分。
五、阿拉伯小写金额数字前面,均应填写人民币符号“¥”(或草写:¥)。阿拉伯小写金额数字要认真填写,不得连写分辩不清。
进制关系表:
┌─┬─┬─┬───┐
│小│简│繁│ 进制 │
├─┼─┼─┼───┤
│一│壹│壹│ 1 │
├─┼─┼─┼───┤
│二│贰│貳│ 2 │
├─┼─┼─┼───┤
│三│叁│叄│ 3 │
├─┼─┼─┼───┤
│四│肆│肆│ 4 │
├─┼─┼─┼───┤
│五│伍│伍│ 5 │
├─┼─┼─┼───┤
│六│陆│陸│ 6 │
├─┼─┼─┼───┤
│七│柒│柒│ 7 │
├─┼─┼─┼───┤
│八│捌│捌│ 8 │
├─┼─┼─┼───┤
│九│玖│玖│ 9 │
├─┼─┼─┼───┤
│十│十│拾│ 10 │
├─┼─┼─┼───┤
│百│佰│佰│ 100 │
├─┼─┼─┼───┤
│千│仟│仟│ 1000 │
├─┼─┼─┼───┤
│万│万│萬│ 10^4 │
├─┼─┼─┼───┤
│亿│亿│億│ 10^8 │
├─┼─┼─┼───┤
│兆│兆│兆│ 10^12│
└─┴─┴─┴───┘
详见: http://wiki.keyin.cn/index.php?title=%E4%B8%AD%E6%96%87%E6%95%B0%E5%AD%97&variant=zh-cn
I see that there are more and more discussions about challenging batch processing algorithms in the forum, and there are also a group of brothers who are enthusiastic about exploring the potential of batch processing. I am very happy that some tasks not very suitable for batch processing are gradually being completed by batch processing.
Now I plan a topic - converting digital amounts to uppercase. This topic can almost find versions in any popular language on the Internet, but there is a lack of a batch processing version. Of course, we can't expect foreigners to do this, and then we can learn from it ^_^.
The rules are as follows:
1. Receive a string of amount numbers and convert them to uppercase. The possible reasonable formats are 5821564130 or 5821564.130 or 5,821,564.130, etc.
There will be no numbers with unclear decimal places such as 58.215.64.130 or other non-amount digital characters.
2. The maximum digit is up to one hundred billion, and the minimum digit is up to cents, and the digits after cents are ignored.
3. It should be completed purely by batch processing under CMD without using third-party tools.
4. The specific conversion basis is as per the appendix.
Appendix:
Basic Regulations for Correctly Filling Out Bills and Settlement Vouchers
Bills and settlement vouchers filled out by banks, units, and individuals are important bases for handling payment settlements and cash receipts and payments, directly related to the accuracy, timeliness, and safety of payment settlements. Bills and settlement vouchers are accounting vouchers for banks, units, and individuals to record accounts, and are a written certificate for recording economic business and clarifying economic responsibilities. Therefore, when filling out bills and settlement vouchers, they must be standardized and standardized, with complete elements, correct numbers, clear handwriting, no omissions or mistakes, no scribbles, and prevention of alteration.
1. Chinese capital amount numbers should be filled in with regular script or running script, such as壹 (壹), 贰 (貳), 叁 (參), 肆 (肆), 伍 (伍), 陆 (陸), 柒, 捌, 玖, 拾, 佰, 仟, 万 (萬), 亿, 元, 角, 分, 零, 整 (正), etc. Words like 一, 二 (两), 三, 四, 五, 六, 七, 八, 九, 十, 念, 毛, 另 (or 0) should not be used, and simplified characters should not be made up. If complex characters such as 贰, 陆, 亿, 万, 圆 are used in the writing of amount numbers, they should also be accepted.
2. If the Chinese capital amount number ends with "yuan", the word "整" (or "正") should be written after "yuan". After "jiao", the word "整" (or "正") may not be written. If there is "fen" in the capital amount number, the word "整" (or "正") is not written after "fen".
3. The words "Renminbi" should be marked before the Chinese capital amount number. If there is "fen" in the capital amount number, the word "整" (or "正") is not written after "fen".
4. The words "Renminbi" should be marked before the Chinese capital amount number. The Chinese capital amount number should be filled in immediately after the words "Renminbi" without leaving blanks. If the words "Renminbi" are not pre-printed in the capital amount column of bills and settlement vouchers, the words "Renminbi" should be added. The fixed words such as 仟, 佰, 拾, 万, 仟, 佰, 拾, 元, 角, 分 should not be pre-printed in the capital amount column of bills and settlement vouchers.
5. When there is "0" in the Arabic lowercase amount number, the Chinese capital should be written according to the rules of the Chinese language, the composition of the amount number, and the requirement to prevent alteration. Examples are as follows:
(1) When there is "0" in the middle of the Arabic number, the Chinese capital amount should write the word "zero". For example, ¥1,409.50 should be written as Renminbi壹仟肆佰零玖元伍角.
(2) When there are several consecutive "0" in the Arabic number, only one word "zero" can be written in the middle of the Chinese capital amount. For example, ¥6,007.14 should be written as Renminbi陆仟零柒元壹角肆分.
(3) When the ten-thousand digit or yuan digit of the Arabic amount number is "0", or there are several consecutive "0" in the middle of the number, and the ten-thousand digit and yuan digit are also "0", but the thousand digit and jiao digit are not "0", only one zero word can be written in the Chinese capital amount, or the word "zero" may not be written. For example, ¥1,680.32 should be written as Renminbi壹仟陆佰捌拾元零叁角贰分, or written as Renminbi壹仟陆佰捌拾元叁角贰分; another example, ¥107,000.53 should be written as Renminbi壹拾万柒仟元零伍角叁分, or written as Renminbi壹拾万零柒仟元伍角叁分.
(4) When the jiao digit of the Arabic amount number is "0" and the fen digit is not "0", the word "zero" should be written after "yuan" in the Chinese capital amount. For example, ¥16,409.02 should be written as Renminbi壹万陆仟肆佰零玖元零贰分; another example, ¥325.04 should be written as Renminbi叁佰贰拾伍元零肆分.
5. The Chinese yuan symbol "¥" (or cursive: ¥) should be filled in before the Arabic lowercase amount number. The Arabic lowercase amount number should be filled in carefully, and should not be written continuously and unclear.
Hexadecimal relationship table:
┌─┬─┬─┬───┐
│Small│Simple│Complex│ Hexadecimal │
├─┼─┼─┼───┤
│One│壹│壹│ 1 │
├─┼─┼─┼───┤
│Two│贰│貳│ 2 │
├─┼─┼─┼───┤
│Three│叁│叄│ 3 │
├─┼─┼─┼───┤
│Four│肆│肆│ 4 │
├─┼─┼─┼───┤
│Five│伍│伍│ 5 │
├─┼─┼─┼───┤
│Six│陆│陸│ 6 │
├─┼─┼─┼───┤
│Seven│柒│柒│ 7 │
├─┼─┼─┼───┤
│Eight│捌│捌│ 8 │
├─┼─┼─┼───┤
│Nine│玖│玖│ 9 │
├─┼─┼─┼───┤
│Ten│十│拾│ 10 │
├─┼─┼─┼───┤
│Hundred│佰│佰│ 100 │
├─┼─┼─┼───┤
│Thousand│仟│仟│ 1000 │
├─┼─┼─┼───┤
│Ten thousand│万│萬│ 10^4 │
├─┼─┼─┼───┤
│Hundred million│亿│億│ 10^8 │
├─┼─┼─┼───┤
│Trillion│兆│兆│ 10^12│
└─┴─┴─┴───┘
For details: http://wiki.keyin.cn/index.php?title=%E4%B8%AD%E6%96%87%E6%95%B0%E5%AD%97&variant=zh-cn
|

☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
|
|
2007-1-1 05:58 |
|
|
youxi01
高级用户
   
积分 846
发帖 247
注册 2006-10-27 来自 湖南==》广东
状态 离线
|
 『第 2 楼』:
使用 LLM 解释/回答一下
写了一段到头来连自己都“看不懂”的代码:
::code by youxi01@cn-dos.net
::date 2006-1-1(Happy new year!best wishes to everyone!)
@echo off
setlocal enabledelayedexpansion
set /a a=0,b=0,c=0
::================================
::设置单位名称;
SET NAME0=仟
SET NAME1=佰
SET NAME2=拾
SET NAME3=
::================================
::=============================================
::设置数字对应的大写中文汉字
for %%i in (零 壹 贰 叁 肆 伍 陆 柒 捌 玖) do (
set BIG!a!=%%i
set /a a+=1)
::=============================================
::=======================================================================
::在以下“函数”的处理过程中,要用到"#"对数字进行对齐(都成四位),以便截取;
::这里设置凡是出现"#"的地方都设置为空。
set BIG#=
::=======================================================================
set EN=
::====================================================
::这里对输入的数字进行处理,分别取出整数部分和小数部分;
set /p EN=请输入金钱数(1000亿以内):
for /f "tokens=1,2* delims=." %%i in ("%EN%") do (
set "round=%%i"
set "dec=%%j00" 2>nul)
::=====================================================
set /a round=%round:,=%
set dec=%dec:~0,2%
:test
set /a b+=1
::=============================================
::每四位数字为一组,对原来的数据进行截取;
if %round% gtr 9999 (
set num!b!=!round:~-4!
set round=!round:~0,-4!
goto :test) else set num!b!=!round!
::==============================================
::=====================================================
::分别对1、2、3段数据进行处理;分别赋予单位:元、万、亿
::同时,分别将返回的数据传给str1,str2,str3(利用%3来控制)。
call :test1 %num1% 元 1
call :test1 %num2% 万 2
call :test1 %num3% 亿 3
::======================================================
::====================================================================
::去掉数字大写里多余的"零"。比如,1002,处理后读出来为:"壹千零贰元整"
::符合我们中国人一般的读数方法;同时将结果分别传入str1,str2,str3(%2控制)。
call :test2 %str1% 1
call :test2 %str2% 2
call :test2 %str3% 3
::=====================================================================
::==============================================================
::防止类似2,0000,1002.00形式出现错误(错误读为:2亿万1千零2元整)
if "!str2!"=="零万" set str2=零
::===============================================================
set str=%str3%%str2%%str1%
set str=%str:零元=元%
set str=%str:零万=万%
set str=%str:零亿=亿%
::防止整数部分为0;
if "%str%"=="元" set str=零元
::对小数部分数字进行处理;
if "%dec%"=="00" (set dec=整) else (
set /a dec1=!dec:~0,1!
set /a dec2=!dec:~1,1!
if !dec1! EQU 0 (set dec1=零) else call set dec1=%%BIG!dec1!%%角
if !dec2! EQU 0 (set dec2=) else call set dec2=%%BIG!dec2!%%分
set dec=!dec1!!dec2!
)
echo.
echo ========================
echo 你输入的金钱数目大写为:
echo.
echo %str:零零=零%%dec%
echo ========================
pause>nul
:test1
if not "%1"=="" (
set temp=####%1
set temp=!temp:~-4!
for /l %%i in (0 1 3) do (
set tmp%%i=!temp:~%%i,1!
if defined tmp%%i (
if !tmp%%i! GTR 0 (call set str%3=!str%3!%%BIG!tmp%%i!%%!NAME%%i!) else (
call set str%3=!str%3!%%BIG!tmp%%i!%%)))
set str%3=!str%3!%2
) else set str%3=
goto :eof
:test2
set tmp=%1
set tmp=%tmp:零零=零%
set str%2=%tmp:零零=零%
Last edited by youxi01 on 2007-1-1 at 11:04 PM ]
Wrote a piece of code that in the end even I "can't understand":
::code by youxi01@cn-dos.net
::date 2006-1-1(Happy new year!best wishes to everyone!)
@echo off
setlocal enabledelayedexpansion
set /a a=0,b=0,c=0
::================================
::Set unit name;
SET NAME0=Qian
SET NAME1=Bai
SET NAME2=Shi
SET NAME3=
::================================
::=============================================
::Set the corresponding Chinese characters in uppercase for numbers
for %%i in (Zero One Two Three Four Five Six Seven Eight Nine) do (
set BIG!a!=%%i
set /a a+=1)
::=============================================
::=======================================================================
::In the processing of the following "functions", "#" is used to align numbers (all to four digits) for interception;
::Here, set the place where "#" appears to be empty.
set BIG#=
::=======================================================================
set EN=
::====================================================
::Here, process the input number, and take out the integer part and decimal part respectively;
set /p EN=Please enter the amount of money (within 100 billion):
for /f "tokens=1,2* delims=." %%i in ("%EN%") do (
set "round=%%i"
set "dec=%%j00" 2>nul)
::=====================================================
set /a round=%round:,=%
set dec=%dec:~0,2%
:test
set /a b+=1
::=============================================
::Take out four digits as a group, intercept the original data;
if %round% gtr 9999 (
set num!b!=!round:~-4!
set round=!round:~0,-4!
goto :test) else set num!b!=!round!
::==============================================
::=====================================================
::Process the 1st, 2nd, 3rd segments of data respectively; assign units: Yuan, Ten Thousand, Hundred Million
::At the same time, pass the returned data to str1, str2, str3 respectively (controlled by %3).
call :test1 %num1% Yuan 1
call :test1 %num2% Ten Thousand 2
call :test1 %num3% Hundred Million 3
::======================================================
::====================================================================
::Remove the excess "Zero" in the uppercase of numbers. For example, 1002, after processing, it is read as: "One Thousand Zero Two Yuan Only"
::Conforms to the general reading method of Chinese people; at the same time, pass the result to str1, str2, str3 respectively (%2 control).
call :test2 %str1% 1
call :test2 %str2% 2
call :test2 %str3% 3
::=====================================================================
::==============================================================
::Prevent errors like 2,0000,1002.00 from appearing (incorrectly read as: 2 Hundred Million 1 Thousand Zero 2 Yuan Only)
if "!str2!"=="Zero Ten Thousand" set str2=Zero
::===============================================================
set str=%str3%%str2%%str1%
set str=%str:Zero Yuan=Yuan%
set str=%str:Zero Ten Thousand=Ten Thousand%
set str=%str:Zero Hundred Million=Hundred Million%
::Prevent the integer part from being 0;
if "%str%"=="Yuan" set str=Zero Yuan
::Process the decimal part number;
if "%dec%"=="00" (set dec=Only) else (
set /a dec1=!dec:~0,1!
set /a dec2=!dec:~1,1!
if !dec1! EQU 0 (set dec1=Zero) else call set dec1=%%BIG!dec1!%%Jiao
if !dec2! EQU 0 (set dec2=) else call set dec2=%%BIG!dec2!%%Cent
set dec=!dec1!!dec2!
)
echo.
echo ========================
echo The uppercase of the amount you entered is:
echo.
echo %str:Zero Zero=Zero%%dec%
echo ========================
pause>nul
:test1
if not "%1"=="" (
set temp=####%1
set temp=!temp:~-4!
for /l %%i in (0 1 3) do (
set tmp%%i=!temp:~%%i,1!
if defined tmp%%i (
if !tmp%%i! GTR 0 (call set str%3=!str%3!%%BIG!tmp%%i!%%!NAME%%i!) else (
call set str%3=!str%3!%%BIG!tmp%%i!%%)))
set str%3=!str%3!%2
) else set str%3=
goto :eof
:test2
set tmp=%1
set tmp=%tmp:Zero Zero=Zero%
set str%2=%tmp:Zero Zero=Zero%
Last edited by youxi01 on 2007-1-1 at 11:04 PM ]
此帖被 +43 点积分 点击查看详情 评分人:【 无奈何 】 | 分数: +20 | 时间:2007-1-1 12:55 | 评分人:【 redtek 】 | 分数: +11 | 时间:2007-1-2 02:37 | 评分人:【 namejm 】 | 分数: +12 | 时间:2007-1-2 04:29 |
|
|
|
2007-1-1 12:02 |
|
|
tigerpower
中级用户
   大师兄
积分 377
发帖 99
注册 2005-8-26
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
哈哈,厉害厉害!!!
去掉空行共63行,不是很长!!!
用纯粹的批处理能写出这样的程序,精彩!!!佩服!!!
美中不足有二:
1. "十"、"百"、"千"应为"拾"、"佰"、"仟",这是语文的问题,应该不算bug:)
2. 当输入是0.xx时好像有点问题。
Hehe, amazing!!!!
There are 63 lines after removing blank lines, not very long!!!!
It's wonderful to be able to write such a program with pure batch processing, amazing!!!! Admiring!!!!
The only two minor drawbacks are:
1. "十", "百", "千" should be "拾", "佰", "仟", this is a Chinese language issue, should not be considered a bug :)
2. There seems to be some issues when the input is 0.xx
|
|
2007-1-1 12:43 |
|
|
youxi01
高级用户
   
积分 846
发帖 247
注册 2006-10-27 来自 湖南==》广东
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
谢谢楼上的提醒,已更正!
Thanks for the reminder from the upstairs, it has been corrected!
|
|
2007-1-1 12:50 |
|
|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
RE youxi01
兄的代码转换效果非常不错。
初步测试,非常合乎规范要求,加分鼓励。
还有一点建议,帖完整功能的批处理时,推荐属上自己的名字与出处地址等,当多次转贴后,别人发现问题或想与作者交流时不因无处联系作者而苦恼,当然也会更好的保护你的劳动成果。推荐的格式为 作者@论坛 这样的形式,以上只是建议仅供参考。
RE tigerpower
零开头的数字,不为合理的金额,可以忽略,当然去除掉也不是很困难的事。
Last edited by 无奈何 on 2007-1-1 at 01:05 PM ]
RE youxi01
Brother's code conversion effect is very good.
Preliminary test, very compliant with the requirements, plus points for encouragement.
There is also a suggestion. When posting a complete batch processing of functions, it is recommended to attach your own name and source address, etc. When multiple reposts are made, others will not be distressed because there is no way to contact the author when they find problems or want to communicate with the author, and of course, it will better protect your work. The recommended format is "Author@Forum" and so on. The above is just a suggestion for reference.
RE tigerpower
Numbers starting with zero are not reasonable amounts and can be ignored. Of course, it is not very difficult to remove them.
Last edited by 无奈何 on 2007-1-1 at 01:05 PM ]
|

☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
|
|
2007-1-1 12:54 |
|
|
qzwqzw
银牌会员
     天的白色影子
积分 2343
发帖 636
注册 2004-3-6
状态 离线
|
 『第 6 楼』:
使用 LLM 解释/回答一下
凑个热闹吧
采用分步替换的原则,一则简化算法,二则易于控制(比如零元——元零的替换)
特意将兆省略了,因为很少有如此多的人民币金额
而且对于京、兆之类的词汇有多种解释
很多时候一兆等于一百万(1M),也有时候一兆等于一亿亿
另外,有谁有兴趣编个反向转换算法?
以及相关的罗马数字与阿拉伯数字的相互转换?
:: 人民币金额小写转大写
:: qzwqzw@bbs.cn-dos.net
:: 2007-01-01
@echo off
setlocal EnableDelayedExpansion
set tbl1=零壹贰叁肆伍陆柒捌玖
set tbl2=分角元拾佰仟万拾佰仟亿拾佰仟
:test
setlocal
set /p num=请输入金额(小于一万亿元):
for /f "tokens=1,2 delims=." %%f in ("%num%") do (
set num2=%%g00
set num=%%f!num2:~0,2!
)
:loop
call set rmb=%%tbl1:~%num:~-1,1%,1%%%%tbl2:~%bit%,1%%%rmb%
set /a bit+=1
set num=%num:~0,-1%
if not "%num%"=="" goto loop
set rmb=%rmb:零拾=零%
set rmb=%rmb:零佰=零%
set rmb=%rmb:零仟=零%
set rmb=%rmb:零零=零%
set rmb=%rmb:零零=零%
set rmb=%rmb:零元=元零%
set rmb=%rmb:零万=万零%
set rmb=%rmb:零亿=亿零%
set rmb=%rmb:零零=零%
set rmb=%rmb:零分=零%
set rmb=%rmb:零角=零%
set rmb=%rmb:角零=角%
set rmb=%rmb:零零=整%
echo 人民币%rmb%
endlocal
goto test
Last edited by qzwqzw on 2007-1-1 at 11:29 AM ]
Join in the fun
Adopt the principle of step-by-step replacement, on the one hand, simplify the algorithm, on the other hand, it is easy to control (such as the replacement of zero yuan - yuan zero)
Deliberately omitted the term "trillion" because there are very few RMB amounts with such a large value
Moreover, there are multiple interpretations of terms like "jing" and "trillion"
Many times one trillion equals one million (1M), and sometimes one trillion equals one hundred million million
Is there anyone interested in compiling a reverse conversion algorithm?
And the mutual conversion between Roman numerals and Arabic numerals?
:: Convert lowercase RMB amount to uppercase
:: qzwqzw@bbs.cn-dos.net
:: 2007-01-01
@echo off
setlocal EnableDelayedExpansion
set tbl1=Zero One Two Three Four Five Six Seven Eight Nine
set tbl2=Cent Jiao Yuan Ten Hundred Thousand Ten Hundred Thousand Hundred Million Ten Hundred Thousand
:test
setlocal
set /p num=Please enter the amount (less than one trillion yuan):
for /f "tokens=1,2 delims=." %%f in ("%num%") do (
set num2=%%g00
set num=%%f!num2:~0,2!
)
:loop
call set rmb=%%tbl1:~%num:~-1,1%,1%%%%tbl2:~%bit%,1%%%rmb%
set /a bit+=1
set num=%num:~0,-1%
if not "%num%"=="" goto loop
set rmb=%rmb:Zero Ten=Zero%
set rmb=%rmb:Zero Hundred=Zero%
set rmb=%rmb:Zero Thousand=Zero%
set rmb=%rmb:Zero Zero=Zero%
set rmb=%rmb:Zero Zero=Zero%
set rmb=%rmb:Zero Yuan=Yuan Zero%
set rmb=%rmb:Zero Ten Thousand=Ten Thousand Zero%
set rmb=%rmb:Zero Hundred Million=Hundred Million Zero%
set rmb=%rmb:Zero Zero=Zero%
set rmb=%rmb:Zero Cent=Zero%
set rmb=%rmb:Zero Jiao=Zero%
set rmb=%rmb:Jiao Zero=Jiao%
set rmb=%rmb:Zero Zero=Only%
echo RMB%rmb%
endlocal
goto test
Last edited by qzwqzw on 2007-1-1 at 11:29 AM ]
此帖被 +38 点积分 点击查看详情 评分人:【 无奈何 】 | 分数: +20 | 时间:2007-1-2 01:06 | 评分人:【 namejm 】 | 分数: +16 | 时间:2007-1-2 04:28 | 评分人:【 tghksj 】 | 分数: +2 | 时间:2007-1-3 03:27 |
|
|
|
2007-1-2 00:23 |
|
|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
RE qzwqzw
兄的代码也同样非常出色,并且极其简洁。
金额中含有 “,” 时会出错,“,” 也为合理的金额字符,请稍加完善一下。
兆的概念中国传统和国际单位是不同的,中国传统为一万亿。
详情可以参考下一楼给出的链接。
Last edited by 无奈何 on 2007-1-2 at 01:10 AM ]
RE qzwqzw
Brother's code is also very excellent and extremely concise.
There will be errors when there are "," in the amount, and "," is also a reasonable amount character, please improve it a little.
The concept of "兆" is different between traditional Chinese and international units. In traditional Chinese, it is 1000000000000.
For details, you can refer to the link given in the next floor.
Last edited by 无奈何 on 2007-1-2 at 01:10 AM ]
|

☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
|
|
2007-1-2 01:02 |
|
|
qzwqzw
银牌会员
     天的白色影子
积分 2343
发帖 636
注册 2004-3-6
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
加了一些验证代码,很影响代码的简洁,有些郁闷
可以通过带有前缀0的数字,含,的数字,以.前缀的小数
可以禁止含有非法字符的金额
-----------------------------------------------------------------
国际单位的量级是没有兆的,只有m/K/M等
最早是谁将M译为“兆”的已经很难考证
但现在已经很流行,某些会计学教材也开始采用
------------------------------------------------------------------------
至于中国传统的计数,你可以用“亿、兆、京、垓”百度一下
--------------------------------------------------------------------------
:: 人民币金额小写转大写
:: qzwqzw@bbs.cn-dos.net
:: 2007-01-01
@echo off
setlocal EnableDelayedExpansion
set tbl1=零壹贰叁肆伍陆柒捌玖
set tbl2=分角元拾佰仟万拾佰仟亿拾佰仟
:test
cls
setlocal
set /p num=请输入小写金额(小于一万亿元,直接回车退出):
if "%num%"=="" goto :eof
set num=%num:,=%
set num=0%num%
for /f "tokens=1,2,* delims=." %%f in ("%num%") do (
set num2=%%g00
set num=%%f!num2:~0,2!
if not "%%h"=="" goto :error
)
:del_pre0
if not "%num:~0,1%"=="0" goto checknum
set num=%num:~1%
goto del_pre0
:checknum
set /a num2=num+0
if "%num%"=="%num2%" goto loop
:error
echo.
echo 输入小写金额无效!
echo.
pause
goto test
:loop
call set rmb=%%tbl1:~%num:~-1,1%,1%%%%tbl2:~%bit%,1%%%rmb%
set /a bit+=1
set num=%num:~0,-1%
if not "%num%"=="" goto loop
set rmb=%rmb:零拾=零%
set rmb=%rmb:零佰=零%
set rmb=%rmb:零仟=零%
set rmb=%rmb:零零=零%
set rmb=%rmb:零零=零%
set rmb=%rmb:零元=元零%
set rmb=%rmb:零万=万零%
set rmb=%rmb:零亿=亿零%
set rmb=%rmb:零零=零%
set rmb=%rmb:零分=零%
set rmb=%rmb:零角=零%
set rmb=%rmb:角零=角%
set rmb=%rmb:零零=整%
echo.
echo 人民币%rmb%
echo.
pause
endlocal
goto test
Last edited by qzwqzw on 2007-1-1 at 12:36 PM ]
Added some verification code, which has a great impact on the conciseness of the code, a bit郁闷
Can pass numbers with prefix 0, numbers with commas, decimals with. prefix
Can prohibit amounts containing illegal characters
-----------------------------------------------------------------
The magnitude of the international unit does not have giga, only m/K/M, etc.
It is very difficult to verify who first translated M as "giga"
But now it is very popular, and some accounting textbooks have begun to adopt it
------------------------------------------------------------------------
As for the traditional Chinese counting, you can use "hundred million, giga, jing, gai" Baidu it
--------------------------------------------------------------------------
:: RMB amount lowercase to uppercase
:: qzwqzw@bbs.cn-dos.net
:: 2007-01-01
@echo off
setlocal EnableDelayedExpansion
set tbl1=Zero One Two Three Four Five Six Seven Eight Nine
set tbl2=Cent Jiao Yuan Ten Hundred Thousand Ten Hundred Thousand Hundred Billion Ten Hundred Thousand
:test
cls
setlocal
set /p num=Please enter the lowercase amount (less than 100 billion, press Enter to exit):
if "%num%"=="" goto :eof
set num=%num:,=%
set num=0%num%
for /f "tokens=1,2,* delims=." %%f in ("%num%") do (
set num2=%%g00
set num=%%f!num2:~0,2!
if not "%%h"=="" goto :error
)
:del_pre0
if not "%num:~0,1%"=="0" goto checknum
set num=%num:~1%
goto del_pre0
:checknum
set /a num2=num+0
if "%num%"=="%num2%" goto loop
:error
echo.
echo Invalid lowercase amount!
echo.
pause
goto test
:loop
call set rmb=%%tbl1:~%num:~-1,1%,1%%%%tbl2:~%bit%,1%%%rmb%
set /a bit+=1
set num=%num:~0,-1%
if not "%num%"=="" goto loop
set rmb=%rmb:Zero Ten=Zero%
set rmb=%rmb:Zero Hundred=Zero%
set rmb=%rmb:Zero Thousand=Zero%
set rmb=%rmb:Zero Zero=Zero%
set rmb=%rmb:Zero Zero=Zero%
set rmb=%rmb:Zero Yuan=Yuan Zero%
set rmb=%rmb:Zero Ten Thousand=Ten Thousand Zero%
set rmb=%rmb:Zero Hundred Million=Hundred Million Zero%
set rmb=%rmb:Zero Zero=Zero%
set rmb=%rmb:Zero Cent=Zero%
set rmb=%rmb:Zero Jiao=Zero%
set rmb=%rmb:Jiao Zero=Jiao%
set rmb=%rmb:Zero Zero=Only%
echo.
echo RMB%rmb%
echo.
pause
endlocal
goto test
Last edited by qzwqzw on 2007-1-1 at 12:36 PM ]
|
|
2007-1-2 01:28 |
|
|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
RE qzwqzw
简单了解一下,传统的计数以十进制的。上面的表格称作现行通常用的好像比较合适。超大的数字也不太常用,仅当作趣闻知识吧。
RE qzwqzw
A brief understanding: traditional counting is in decimal. The above table is called the current commonly used one, which seems appropriate. Extremely large numbers are not commonly used either, just as anecdotal knowledge.
|

☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
|
|
2007-1-2 12:54 |
|
|
qzwqzw
银牌会员
     天的白色影子
积分 2343
发帖 636
注册 2004-3-6
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
做了一个简单的阿拉伯数字转罗马数字的例子
考虑到规则的不统一和算法的复杂性,没有支持49->IL之类的转化
也没有支持超过4000的数字
反向转换相对困难一些
不过一旦建立了良好的数据结构,算法也就很清晰了
:: Arab2Roman 阿拉伯数字转为罗马数字
:: qzwqzw @ http://bbs.cn-dos.net
:: 2007-01-02 Revision 3
@echo off
setlocal EnableDelayedExpansion
:test
if "%~0"=="%~f0" cls
setlocal
set /p num=请输入阿拉伯数字num("0<num<4000",直接回车退出):
if "%num%"=="" goto :eof
:checknum
set /a tmp=num+0
if "%num%"=="%tmp%" if %num% lss 4000 if %num% gtr 0 goto Arab2Roman
:error
echo.
echo 无效的数字
echo.
if "%~0"=="%~f0" pause
endlocal
goto test
:Arab2Roman
set i=0
for %%v in (1000 900 500 400 100 90 50 40 10 9 5 4 1) do (
set /a i+=1
set arab!i!=%%v
)
set i=0
for %%v in (M CM D CD C XC L CL X IX V IV I) do (
set /a i+=1
set roman!i!=%%v
)
set i=1
:loop
call set tmp=%%arab%i%%%
if 1%num% lss 1%tmp% (
set /a i+=1
) else (
call set rom=%rom%%%roman%i%%%
set /a num-=tmp
)
if 1%num% gtr 10 goto loop
::Arab2Roman
echo.
echo %rom%
echo.
if "%~0"=="%~f0" pause
endlocal
goto test
Last edited by qzwqzw on 2007-1-2 at 01:17 PM ]
Made a simple example of converting Arabic numerals to Roman numerals
Considering the inconsistency of rules and the complexity of the algorithm, it does not support conversions like 49->IL
Also does not support numbers exceeding 4000
Reverse conversion is relatively more difficult
But once a good data structure is established, the algorithm is clear
:: Arab2Roman Convert Arabic numerals to Roman numerals
:: qzwqzw @ http://bbs.cn-dos.net
:: 2007-01-02 Revision 3
@echo off
setlocal EnableDelayedExpansion
:test
if "%~0"=="%~f0" cls
setlocal
set /p num=Please enter Arabic numeral num ("0<num<4000", press Enter directly to exit):
if "%num%"=="" goto :eof
:checknum
set /a tmp=num+0
if "%num%"=="%tmp%" if %num% lss 4000 if %num% gtr 0 goto Arab2Roman
:error
echo.
echo Invalid number
echo.
if "%~0"=="%~f0" pause
endlocal
goto test
:Arab2Roman
set i=0
for %%v in (1000 900 500 400 100 90 50 40 10 9 5 4 1) do (
set /a i+=1
set arab!i!=%%v
)
set i=0
for %%v in (M CM D CD C XC L CL X IX V IV I) do (
set /a i+=1
set roman!i!=%%v
)
set i=1
:loop
call set tmp=%%arab%i%%%
if 1%num% lss 1%tmp% (
set /a i+=1
) else (
call set rom=%rom%%%roman%i%%%
set /a num-=tmp
)
if 1%num% gtr 10 goto loop
::Arab2Roman
echo.
echo %rom%
echo.
if "%~0"=="%~f0" pause
endlocal
goto test
Last edited by qzwqzw on 2007-1-2 at 01:17 PM ]
|
|
2007-1-3 01:54 |
|
|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
|
2007-1-3 02:05 |
|
|
tghksj
社区乞丐
此图片另存后死机
积分 -49
发帖 90
注册 2006-12-2
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
怎么又是 qzwqzw
我现在快成了你的FANS了.
你出一段代码,就够我看个一两天的....
老样子加上两分,拿回家看...
Why is it again qzwqzw
I'm almost becoming your FANS now.
You write a piece of code, which can keep me occupied for a day or two....
As usual, add two points, take it home to read...
|

我的网络笔记本.[color=Red]非联系本人请勿访问![/color]http://w.vicp.net[img]http://zhenlove.com.cn/cndos/fileup/files/QM2.jpg[/img] |
|
2007-1-3 03:26 |
|
|
flamey
初级用户
 
积分 152
发帖 74
注册 2005-12-1
状态 离线
|
|
2007-1-3 04:51 |
|
|
qzwqzw
银牌会员
     天的白色影子
积分 2343
发帖 636
注册 2004-3-6
状态 离线
|
|
2007-1-3 23:40 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
呵呵,qzwqzw 厉害。建议把各种类型的转换开成专帖发表,做到专帖专用,这样有利于日后的深入讨论和论坛的检索。
Hehe, qzwqzw is amazing. It is suggested to start special threads for publishing various types of conversions, making each thread dedicated to a specific use. This is conducive to in-depth discussions and forum retrieval in the future.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2007-1-3 23:47 |
|
|