Batch Script - Align Right

This used to align text to the right, which is normally used to improve readability of number columns.


@echo off 
set x = 1000 
set y = 1 
set y = %y% 
echo %x% 

set y = %y:~-4% 
echo %y%

A few key things to note about the above program is −

  • Spaces are added to the variable of y, in this case we are adding 9 spaces to the variable of y.

  • We are using the ~-4 option to say that we just want to show the last 4 characters of the string y.


The above command produces the following output. The key thing to note is that the value of 2 is aligned to match the units columns when displaying numbers.