:: figure.bat
@echo off
setlocal enabledelayedexpansion
set l=0
set m=1
set n=%1
echo %n%|findstr /r "[^0-9\-]" >NUL 2>&1
if %ERRORLEVEL% equ 0 goto :EOF
if %n% lss 0 set /a n*=-1
call :length %n% l
echo 数字の桁数 : %l%
set /a l-=1
for /l %%i in (1,1,%l%) do set /a m=!m!*10
echo 最大桁の位 : %m%
endlocal
goto :EOF
:length
setlocal
set i=0
set t=%1
set t=%t:"=%
:loop
set t=%t:~1%
set /a i+=1
if not "%t%" == "" goto loop
endlocal & set %2=%i%
goto :EOF
silverwire
#5677()
[
Batchfile
]
Rating0/0=0.00
「文字列の反転」でバッチによる文字列長の算出方法を書いたので、それを応用しました。 念のため、引数が数値かどうかチェックしています。加えて、負の整数にも対応しました。 e.g. C:\>figure 1000 数字の桁数 : 4 最大桁の位 : 1000 C:\>figure 100 数字の桁数 : 3 最大桁の位 : 100 C:\>figure 10 数字の桁数 : 2 最大桁の位 : 10 C:\>figure 1 数字の桁数 : 1 最大桁の位 : 1 C:\>figure -1 数字の桁数 : 1 最大桁の位 : 1 C:\>figure -10 数字の桁数 : 2 最大桁の位 : 10 C:\>figure -100 数字の桁数 : 3 最大桁の位 : 100 C:\>figure -1000 数字の桁数 : 4 最大桁の位 : 1000 遅延環境変数展開を利用しているので、Windows NTでは動作しません。Windows XPで動作 を確認。:: figure.bat @echo off setlocal enabledelayedexpansion set l=0 set m=1 set n=%1 echo %n%|findstr /r "[^0-9\-]" >NUL 2>&1 if %ERRORLEVEL% equ 0 goto :EOF if %n% lss 0 set /a n*=-1 call :length %n% l echo 数字の桁数 : %l% set /a l-=1 for /l %%i in (1,1,%l%) do set /a m=!m!*10 echo 最大桁の位 : %m% endlocal goto :EOF :length setlocal set i=0 set t=%1 set t=%t:"=% :loop set t=%t:~1% set /a i+=1 if not "%t%" == "" goto loop endlocal & set %2=%i% goto :EOFRating0/0=0.00-0+
[ reply ]