The initial post that prompted this development was a ptyhon program found here: https://github.com/DoctorLai/PyUtils/bl ... er/zDiv.py - so the algorithm credit belongs to him and not me.
file:Divide.cmd
usage: Divide Number Number Precision
Code: Select all
@echo off
echo.
:: catch missing parameters
if "%3"=="" goto help
if "%2"=="" goto help
if "%1"=="" goto help
:: check for positive integers
if not %1 GTR 0 goto help
if not %2 GTR 0 goto help
if not %3 GTR 0 goto help
goto :continue
:help
echo You need three parameters, Top Divisor, Bottom Divisor and ^# of decimal places
echo Example: %0 387 41 20, will divide 387 by 41 out to 20 decimal places. Now you try.
echo Tip: You cannot use a zero "0" for any parameter, all parm's must be positive integers.
goto end
:continue
setlocal enableextensions enabledelayedexpansion
:: all Variables are self explained
set /a TopDiv=%1
set /a BotDiv=%2
set /a Precis=%3 + 1
set /a DivRsl=TopDiv / BotDiv
set Solution=%TopDiv% / %BotDiv%=%DivRsl%.
:DivideMe
set /a TopDiv=(TopDiv - DivRsl * BotDiv) * 10
if "%TopDiv%"=="0" goto Finished
set /a DivRsl=TopDiv / BotDiv
set /a Precis=Precis - 1
if "%Precis%"=="0" goto Finished
set Solution=%Solution%%DivRsl%
goto DivideMe
:Finished
for /f "tokens=1-3* delims==." %%a in ('echo "!Solution!"') do (
set Problem=%%a
set Answer=%%b.%%c
echo The solution to !Problem:~1! is !Answer:~0,-1!
)
endlocal
:end
echo.
I hope that it passes muster!