Squashman wrote:goymerac wrote:Thanks, that seems a lot more in-depth than I was thinking. I'd just like to divide !G! by 1074?
So what don't you understand about 32 bit integers. The example you provided is larger than the largest 32 bit integer that SET /A can handle.
You have two choices. You either use the code I provided to do it in pure batch or you pass the values to a vbscript.
I tried this code but with my little knowledge of batch code I could get it to work. The command prompt would just close or display the code.
@ECHO OFF
if "%~1"=="/?" (
echo.&echo USAGE:&echo.
echo "%~0" largenumber smallnumber [variablename] [places]
echo "%~0" largenumber / smallnumber [variablename] [places]
echo.&echo "largenumber" can floating point "smallnumber" can't.
echo Only the first [places] decimal places are used for input or
echo output. if [places] is omitted then the default of 8 is used.
echo.&echo To specify [places] with out [variablename] pass an empty set.
echo Below is an example:
echo.&echo "%~0" 46546545464.123456789 / 1024 "" 9&echo.
echo.&echo "smallnumber" must be below 2097153, "largenumber" can have
echo hundreds of places.&echo.&echo -Judago 2009/2010
exit /b 0
)
SETLOCAL ENABLEDELAYEDEXPANSION
set error=Invalid Input
if "%~1"=="" goto error
if "%~2"=="/" shift /2
if "%~2"=="" goto error
for /f "delims=1234567890." %%a in ("%~1%~2") do goto error
set divisor=%~2
set error=divisor must be whole
if not "!divisor!"=="!divisor:.=!" goto error
if !divisor! gtr 2097152 (
set error=divisor too large, limited to: 2097152
goto error
)
set dplace=%~4
if not defined dplace set dplace=8
for /f "delims=1234567890." %%a in ("%~4") do set dplace=8
set input=0%~1
for /l %%a in (1 1 %dplace%) do set input=!input!0
set error=Divide by zero
if "!divisor:0=!"=="" goto error
set chunk=
set total=
set /a fpos=dplace + 1
:isfloat
if not "!input:.=!"=="!input!" (
if not "!input:~-%fpos%,1!"=="." (
set input=!input:~0,-1!
goto isfloat
) else (
set input=!input:.=!
)
)
:split
if not "%input:~3%"=="" (
set /a chunk+=1
set input!chunk!=%input:~-3%
set input=%input:~0,-3%
if defined input goto split
) else (
set /a chunk+=1
set input!chunk!=%input%
)
:loop
if defined input%chunk% (
if "!input%chunk%:~0,1!"=="0" (
set input%chunk%=!input%chunk%:~1!
goto loop
)
) else (
set input%chunk%=0
goto pad
)
set chunkresult=0
:divide
If !input%chunk%! geq !divisor! (
If !input%chunk%! geq !divisor!000 (
set /a input%chunk%-=!divisor!000
set /a chunkresult+=1000
goto divide
) else (
If !input%chunk%! geq !divisor!00 (
set /a input%chunk%-=!divisor!00
set /a chunkresult+=100
goto divide
) else (
If !input%chunk%! geq !divisor!0 (
set /a input%chunk%-=!divisor!0
set /a chunkresult+=10
goto divide
) else (
set /a input%chunk%-=!divisor!
set /a chunkresult+=1
goto divide
)
)
)
)
:pad
if "!chunkresult:~2,1!"=="" set chunkresult=0!chunkresult!
if "!chunkresult:~2,1!"=="" set chunkresult=0!chunkresult!
set total=%total%%chunkresult%
set chunkresult=0
if %chunk% gtr 0 (
set /a chunk-=1
if !input%chunk%! gtr 0 (
set carry=!input%chunk%!
for %%a in (!chunk!) do set input!chunk!=!carry!!input%%a!
)
)
if %chunk% gtr 0 goto loop
if not defined total set total=0
if %dplace% gtr 0 set total=!total:~0^,-%dplace%!.!total:~-%dplace%!
:finish
if "%total:~0,1%"=="0" if not "%total:~1%"=="" set total=%total:~1%&&goto finish
if "%total:~0,1%"=="." set total=0%total%
if not "%~3"=="" (
endlocal
set %~3=%total%
) else (
echo %total% - Leftover:!input%chunk%! ^(this isn't always the mod result^)
endlocal
)
exit /b 0
:Error
1>&2 echo %error% - See "%~0 /?"
endlocal
exit /b 1