China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-31 12:39
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Joint Participation][Challenge Idea] Batch processing to realize conversion of digital amount to uppercase DigestI View 14,095 Replies 24
Original Poster Posted 2007-01-01 05:58 ·  中国 浙江 宁波 鹏博士宽带
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
21-year member
UID 40733
Gender Male
Status Offline
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

Floor 2 Posted 2007-01-01 12:02 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
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 ]
Recent Ratings for This Post ( 3 in total) Click for details
RaterScoreTime
无奈何 +20 2007-01-01 12:55
redtek +11 2007-01-02 02:37
namejm +12 2007-01-02 04:29
Floor 3 Posted 2007-01-01 12:43 ·  中国 上海 闵行区 电信
中级用户
★★
大师兄
Credits 377
Posts 99
Joined 2005-08-26 07:37
20-year member
UID 41945
Status Offline
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
Floor 4 Posted 2007-01-01 12:50 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
Thanks for the reminder from the upstairs, it has been corrected!
Floor 5 Posted 2007-01-01 12:54 ·  中国 浙江 宁波 鹏博士宽带
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
21-year member
UID 40733
Gender Male
Status Offline
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

Floor 6 Posted 2007-01-02 00:23 ·  中国 江西 南昌 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
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 ]
Recent Ratings for This Post ( 3 in total) Click for details
RaterScoreTime
无奈何 +20 2007-01-02 01:06
namejm +16 2007-01-02 04:28
tghksj +2 2007-01-03 03:27
Floor 7 Posted 2007-01-02 01:02 ·  中国 浙江 宁波 鹏博士宽带
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
21-year member
UID 40733
Gender Male
Status Offline
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

Floor 8 Posted 2007-01-02 01:28 ·  中国 江西 南昌 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
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 ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
tghksj +2 2007-01-03 03:26
Floor 9 Posted 2007-01-02 12:54 ·  中国 浙江 宁波 鹏博士宽带
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
21-year member
UID 40733
Gender Male
Status Offline
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

Floor 10 Posted 2007-01-03 01:54 ·  中国 江西 南昌 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
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 ]
Floor 11 Posted 2007-01-03 02:05 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,179
Posts 442
Joined 2006-09-09 22:47
19-year member
UID 62249
Status Offline
Admiring this great work.
Floor 12 Posted 2007-01-03 03:26 ·  中国 山东 济南 电信
社区乞丐
★★
此图片另存后死机
Credits -49
Posts 90
Joined 2006-12-02 13:00
19-year member
UID 72412
Gender Male
Status Offline
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...
我的网络笔记本.非联系本人请勿访问!http://w.vicp.net
Floor 13 Posted 2007-01-03 04:51 ·  中国 广东 肇庆 电信
初级用户
★★
Credits 152
Posts 74
Joined 2005-12-01 23:06
20-year member
UID 46314
Status Offline
qzwqzw~~~~Impressive!!!!!
Floor 14 Posted 2007-01-03 23:40 ·  中国 山西 运城 联通
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
```

:: Arabic and Roman Numeral Conversion Program
:: qzwqzw http://bbs.cn-dos.net
:: 2007-01-03 Revision 2
@echo off
setlocal EnableDelayedExpansion

for /l %%i in (1,1,100) do (
set /a numin=!random!*4200/32768-100
set in=!numin!
set out=
call :Arab2Roman
set in=!out!
call :Roman2Arab
echo.%%i
if !numin! neq !out! set /p=--- Invalid ---
)
pause
endlocal
goto :eof

:Arab2Roman
setlocal EnableDelayedExpansion
set num=%in%
set /a tmp=num+0
if not "%num%"=="%tmp%" goto :eof
if %num% geq 4000 goto :eof
if %num% leq 0 goto :eof

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 XL X IX V IV I) do (
set /a i+=1
set roman!i!=%%v
)

set i=1
:a2r_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 a2r_loop

endlocal & set out=%rom%
goto :eof
::Arab2Roman

:Roman2Arab
setlocal EnableDelayedExpansion

echo.%in%|findstr /r "">nul && goto :eof

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 1 D 2 C 3 L 4 X 5 V 6 I) do (
set /a i+=1
set roman!i!=%%v
)

set in=%in:m=M%
set in=%in:d=D%
set in=%in:c=C%
set in=%in:l=L%
set in=%in:x=X%
set in=%in:v=V%
set in=%in:i=I%

set in=%in:CM=1%
set in=%in:CD=2%
set in=%in:XC=3%
set in=%in:XL=4%
set in=%in:IX=5%
set in=%in:IV=6%

set i=1
set num=0
:r2a_loop
set tmp=%in:~0,1%
call set rom1=%%roman%i%%%
if "%tmp%"=="%rom1%" (
call set /a num+=arab%i%
set in=%in:~1%
) else (
set /a i+=1
)
if %i% gtr 13 goto :eof
if not "%in%"=="" goto r2a_loop

endlocal & set out=%num%
goto :eof
::Roman2Arab

```
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
namejm +12 2007-01-03 23:47
无奈何 +12 2007-01-04 00:24
Floor 15 Posted 2007-01-03 23:47 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
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没商量。
考虑问题复杂化,解决问题简洁化。
Forum Jump: