我有一个bat文件,它读取记录列表并从每行中提取一个数字。然后它将这些数字写入另一个文本文件,并从此处计算出总值是多少,在读取数字时删除前导0。
这一切都很好,但我似乎无法做到的是因为这个价值是需要2个小数点的价格。目前它以2971480
打印到文件,但我需要它为29714.80
。有没有办法在bat文件中执行此操作?
我使用的代码如下:
setlocal EnableDelayedExpansion
rem.> "C:\output.txt"
for /F "delims=" %%L in ('findstr /L "T" "C:\test files\test.txt"') do (
set "LINE=%%L" & set "LINE=!LINE:*ResponseCode=!" & echo !LINE:~39,8%!
)>> "C:\output.txt"
endlocal
set sum=0
cd C:\test files
for /F "tokens=* delims=0" %%A in (output.txt) do set /a sum=sum+%%A
echo The total Sales for today was %sum% > output2.txt
output2.txt
pause
老实说,我不知道从哪里开始。任何帮助将不胜感激。
修改
原始文件如下所示:
" 59",003005213,23,10,0017,07,59,0000,0000,03,03005213,04,0000,00000000,00000000,00000000,00000000,00000000,00000000,00000000, 00000000,00000000," R" 00000000 " 59",002009205,23,10,0017,08,00,0001,0000,02,02009205,02,0001,00000000,00004300,00000000,00004300,00005000,00005000,00000000,00000000,00000700 " R" 00000000 " 61",0000000001879,00000010,1,00000430,00004300,02,01,0," T",002009205,0 " 59",002009206,23,10,0017,08,02,0001,0000,02,02009206,02,0001,00000000,00001200,00000000,00001200,00001200,00001200,00000000,00000000,00000000 " R" 00000000 " 61",0000000001430,00000001,1,00001200,00001200,02,01,0," T",002009206,0 " 59",003005214,23,10,0017,08,03,0001,0000,03,03005214,02,0001,00000000,00006500,00000000,00006500,00006500,00006500,00000000,00000000,00000000 " R" 00000000 " 61",0000000001428,00000005,1,00001300,00006500,02,01,0," T",003005214,0 " 59",002009207,23,10,0017,08,04,0002,0000,02,02009207,02,0002,00003600,00000000,00000000,00003600,00005000,00005000,00000000,00000000,00001400 " R" 00000000 " 61",0000000000285,00000001,1,00002800,00002800,02,00,0," T",002009207,0 " 61",0000000000430,00000002,1,00000400,00000800,02,00,0," T",002009207,0 " 59",003005215,23,10,0017,08,07,0000,0000,03,03005215,04,0000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000 " R" 00000000 " 59",003005216,23,10,0017,08,09,0000,0000,03,03005216,04,0000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000 " R" 00000000 " 59",002009208,23,10,0017,08,10,0001,0000,02,02009208,02,0001,00007000,00000000,00000000,00007000,00010000,00010000,00000000,00000000,00003000 " R" 00000000 " 61",0000000000337,00000001,1,00007000,00007000,02,00,0," T",002009208,0 " 59",003005217,23,10,0017,08,10,0001,0000,03,03005217,02,0001,00000000,00006500,00000000,00006500,00006500,00006500,00000000,00000000,00000000 " R" 00000000 " 61",0000000001428,00000005,1,00001300,00006500,02,01,0," T",003005217,0
每行以61或59开头。
然后在过滤器之后:
00004300 00001200 00006500 00002800 00000800 00007000 00006500 00002900 00000400 00003250 00000520 00002990 00003250 00001300 00005040 00000470 00000410 00002600 00017000 00002800 00001575 00006500 00002430 00001615 00002150 00000350 00001300 00001435 00006500 00002600 00003250 00001860 00003250 00002985 00000430 00001200 00000860 00000515 00002350 00001300 00001300 00001005 00000865 00000430 00002200 00006500 00002490 00001985 00001300 00013000 00001300 00006500 00001300 00006500 00006500 00001300 00003250 00003925 00001160 00002800 00006500 00002200 00001300 00000430 00003250 00000615 00013000 00005490 00002600 00002510 00001300 00008445 00003250 00004595 00013000 00001000 00001005 00001300 00006500 00001300 00001300 00003255 00000670 00002600 00004400 00002480 00001490 00001950 00002895 00003120 00003525 00003250 00005660 00013000 00001470 00006500 00010810 00003250 00003870 00000550 00000400 00001460 00003250 00001300 00000430 00003250 00000430 00007000 00007165 00026000 00003250 00002445 00006500 00003890 00003390 00003250 00002800 00002395 00005555 00002970 00002700 00003445 00003150 00001520 00000930 00010205 00002945 00003250 00001120 00006500 00001215 00006500 00001980 00001495 00002040 00000400 00003250 00000220 00006500 00003250 00006140 00002600 00009750 00000525 00002405 00001920 00000995 00000430 00000430 00006500 00001965 00006500 00001070 00000810 00000430 00017000 00000485 00002010 00006500 00001105 00003480 00003250 00003250 00010025 00000510 00003250 00007000 00003250 00002320 00006500 00002600 00000650 00010345 00005340 00002995 00001240 00003250 00001005 00006500 00001015 00003250 00005065 00000430 00000580 00000450 00000860 00004550 00000430 00001300 00010560 00000880 00000465 00006500 00000840 00003250 00006060 00002600 00010625 00003250 00000430 00000920 00000930 00002600 00005245 00001300
然后我将它们加在一起,删除前导零以获得我的最终总数。
答案 0 :(得分:2)
echo The total Sales for today was %sum:~0,-2%.%sum:~-2% > output2.txt
即输出sum
,除了最后2个字符和一个点,然后是最后2个字符。