Dos arithmetic

April 2018

Dos arithmetic


Hello, Is there a way to round () in dos batch scripts?


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%


Solved by Solved by auvixa
Published by aakai1056. Latest update on August 11, 2010 at 01:39 AM by aakai1056.
This document, titled "Dos arithmetic," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (
Batch to check if a single file is modified
Batch Script to Delete Old Files