|
Answer» I would like to know how to display a number in reverse using BATCH file programming eg. 20060211 to be displayed as 11206002
My os is winxp pro
THANKS@echo off set number=20060211 set aux=%number%
set REV=
:LOOP if "%aux%"=="0" goto END set last_digit=%aux:~-1% set REV=%REV%%last_digit% set /A aux=%aux%/10 goto LOOP
:END echo The reverse of %number% is %REV%Carlos, thanks for your quick response, but I should have been more specific. The number(date) is generated by the program listed below and would of course change every day
set sDate=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%
but I need the date generated to be in reverse, eg. instaed of 20060212 I would like it displayed as 21206002
ThanksIt's an EASY exercise to replace the line: set number=20060211 for: set sDate=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%
Here is a possible solution:
@echo off set sDate=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2% echo Date: %sDate% set aux=%sDate%
set sDate=
:LOOP if "%aux%"=="0" goto END set last_digit=%aux:~-1% set sDate=%sDate%%last_digit% set /A aux=%aux%/10 goto LOOP
:END echo Reverse Date: %sDate%
P.S. If you copy and paste this code, be carefull with the white spaces at the end of the lines. you must suppress them.Carlos, that worked perfectly
one last question, how would I TAKE this reversed result and divide it by the number 4421 then display the result so that the first 4 digits after the decimal point is displayed.
ps what would you suggest as a good tutorial for laerning this type of programming
thanks again for all your helpMS-DOS haven't decimal numbers, you can do the next:
@echo off set sDate=31216002 <-- replace this line ...
set /A integer=%sDate%/4421 set /A remainder=(%sDate% - 4421*integer)%4421 set /A fracc=10000*remainder/4421
set sol=%integer%.%fracc%
echo Division with four decimasl: %sol%
Sorry, I'm from Spain and here I don't know GOODS books of MS-DOS (I don't know if in your country ...) Perhaps the best book is the documentation:
SET /?
and to know a bit of mathematics
The used formula in the quotient:
D | d r c
is:
D=d*c + rCarlos,thanks again for your great help , this is what i have so far
@echo off set sDate=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2% set aux=%sDate%
set sDate=
:LOOP if "%aux%"=="0" goto END set last_digit=%aux:~-1% set sDate=%sDate%%last_digit% set /A aux=%aux%/10 goto LOOP
:END echo %sDate% set /A integer=%sDate%/4421 set /A remainder=(%sDate% - 4421*integer)%4421 set /A fracc=10000*remainder/4421
set sol=%integer%.%fracc%
echo Division with four decimasl: %sol%
** when I run this I get the answer 7058.5044 which is correct but all I need is the first 4 digits after the decimal point (5044) to be displayed. I also get a missing operator message when the above is run
|