Dos arithmetic
Solved/Closed
Related:
- Dos arithmetic
- Ms dos commands - Guide
- Dos to unix - Guide
- Dos list files - Guide
- Dos network commands - Guide
- Dos config.sys - Guide
2 responses
I was Googling and couldn't resist. A simple for loop would do the job.
(As for getting fractional numbers with DOS, it's possible if you multiply both sides of your equation by ten to the Nth power, then move a decimal in from the right side by N. This would have to be compensated for throughout, as any DOS operations on a fractional number are always rounded down (floor) and "fail". At least it helps when dividing in modular arithmetic.)
set num=10.5
for /f "delims=. tokens=1,2" %%a in ("%num%") do (
set num=%%a
set frac=%%b
)
if %frac:~0,1% GEQ 5 set /a num+=1
echo %num%
(As for getting fractional numbers with DOS, it's possible if you multiply both sides of your equation by ten to the Nth power, then move a decimal in from the right side by N. This would have to be compensated for throughout, as any DOS operations on a fractional number are always rounded down (floor) and "fail". At least it helps when dividing in modular arithmetic.)
set num=10.5
for /f "delims=. tokens=1,2" %%a in ("%num%") do (
set num=%%a
set frac=%%b
)
if %frac:~0,1% GEQ 5 set /a num+=1
echo %num%
rizvisa1
Posts
4478
Registration date
Thursday 28 January 2010
Status
Contributor
Last seen
5 May 2022
766
24 Feb 2010 à 08:50
24 Feb 2010 à 08:50
In DOS there is no round function. It works on purely integer concepts. So play with decimal you would have to get very creative. Have you looked into possibility of using VB Scripting or even a combo of VB scripting and DOS