1、利用set /a去掉日期等數(shù)字前面的0,如:2007-09-25中月份中的09前面的0(當(dāng)然這個(gè)月份是未知的,簡單的說就
是不管前面有沒有0都要保證去掉):
演示代碼:
復(fù)制代碼 代碼如下:
@echo off
set Day=1%date:~5,2%
set /a Day-=100
echo %Day%
pause>nul
另外,還可以(在深入運(yùn)用時(shí),比前一種更有優(yōu)勢(shì)):
復(fù)制代碼 代碼如下:
@echo off
set/a day1=%date:~5,1%,day2=%date:~6,1%
set/a day=%day1%*10+%day2%
echo %day%
pause>nul
2、利用set /a(數(shù)值運(yùn)算 除法中除數(shù)不允許出現(xiàn)0)返回值來設(shè)置數(shù)值運(yùn)算的進(jìn)位標(biāo)志;
演示代碼:
@echo off 2>nul 3>nul
set/a num1=7,num2=2
set/a var=%num1%+%num2%
set /a 1/(%var%/10) echo 大于10 ||echo 小于10
pause>nul
再附一特大數(shù)值的加法運(yùn)算演示代碼:(先補(bǔ)位)
復(fù)制代碼 代碼如下:
@echo offsetlocal enabledelayedexpansion
set num1=984322212445613542523552165432136516565135132354123432987619431469731611346143789
set num2=657973265856194306419643120641631361303163006131061301613061130161300613061130
call :lineup num1
call :lineup num2
set/a flag=0
for /l %%i in (1 1 199) do (
set/a var=!num1:~-%%i,1!+!num2:~-%%i,1!+!flag!
set var=0!var!
set flag=!var:~-2,1!
set str=!var:~-1!!str!
)
for /f "delims=0 tokens=*" %%i in ("!str!") do echo %%i
pause>nul
:lineup obj
for /l %%i in (1 1 200) do set %1=0!%1!
call set %1=!%1:~-200!