我有一个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,100017,07,5900000000,0303005213,04000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,“R”,00000000
“59”,002009205,23,100017,08,0000010000,0202009205,02010000000000430000000043000000050000005000000000000000000700,“R”,00000000
“61”,000000000187900000100,1000004300004300,02,01,0,“T”,002009205,0
“59”,002009206,23,100017,08,02000010000,0202009206,020000000000000000120000000000001000012000000120000001200000000000000000000000000,“R”,00000000
“61”,0000000001430000001,100001000012000,02,01,0,“T”,002009206,0
“59”,003005214,23,100017,08,0300010000,0303005214,02000010000000000650000000650000000650000650000000000000000000000000,“R”,00000000
“61”,00000000014280000005,100001300000006500,02,01,0,“T”,003005214,0
“59”,00200907,23,100017,08,0400020000,0202009207,0200002000030000000000000000360000050000005000000000000000000000001400,“R”,00000000
“61”,000000000028500000001,1000028000028000,02,00,0,“T”,002009207,0
“61”,0000000000 43000000002,100000400000800,02,00,0,“T”,002009207,0
“59”,003005215,23,100017,08,0700000000,0303005215,04000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,“R”,00000000
“59”,003005216,23,100017,08,0900000000,0303005216,04000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,“R”,00000000
“59”,00200908,23,100017,08,10000100000000,0202009208,020000700000000000000000000070000001000000000000000000000000000000000000000003000,“R”,00000000
“61”,0000000000337000001,100007000007000,02,00,0,“T”,002009208,0
“59”,003005217,23,100017,08,100001000000,0303005217,02000010000000000650000000650000000650000650000000000000000000000000,“R”,00000000
“61”,00000000014280000005,100001300000006500,02,01,0,“T”,003005217,0
每行以61或59开头。
然后在过滤器之后:
00004300
00001200
00006500
00002800
00000 800
00007000
00006500
00002900
00000 400
00003250
00000 520
00002990
00003250
00001300
00005040
00000 470
00000 410
00002600
00017000
00002800
00001575
00006500
00002430
00001615
00002150
00000 350
00001300
00001435
00006500
00002600
00003250
00001860
00003250
00002985
00000 430
00001200
00000 860
00000 515
00002350
00001300
00001300
00001005
00000 865
00000 430
00002200
00006500
00002490
00001985
00001300
00013000
00001300
00006500
00001300
00006500
00006500
00001300
00003250
00003925
00001160
00002800
00006500
00002200
00001300
00000 430
00003250
00000 615
00013000
00005490
00002600
00002510
00001300
00008445
00003250
00004595
00013000
00001000
00001005
00001300
00006500
00001300
00001300
00003255
00000 670
00002600
00004400
00002480
00001490
00001950
00002895
00003120
00003525
00003250
00005660
00013000
00001470
00006500
00010810
00003250
00003870
00000 550
00000 400
00001460
00003250
00001300
00000 430
00003250
00000 430
00007000
00007165
00026000
00003250
00002445
00006500
00003890
00003390
00003250
00002800
00002395
00005555
00002970
00002700
00003445
00003150
00001520
00000 930
00010205
00002945
00003250
00001120
00006500
00001215
00006500
00001980
00001495
00002040
00000 400
00003250
00000 220
00006500
00003250
00006140
00002600
00009750
00000 525
00002405
00001920
00000 995
00000 430
00000 430
00006500
00001965
00006500
00001070
00000 810
00000 430
00017000
00000 485
00002010
00006500
00001105
00003480
00003250
00003250
00010025
00000 510
00003250
00007000
00003250
00002320
00006500
00002600
00000 650
00010345
00005340
00002995
00001240
00003250
00001005
00006500
00001015
00003250
00005065
00000 430
00000 580
00000 450
00000 860
00004550
00000 430
00001300
00010560
00000 880
00000 465
00006500
00000 840
00003250
00006060
00002600
00010625
00003250
00000 430
00000 920
00000 930
00002600
00005245
00001300
然后我把它们加在一起,去掉前导零,得到最后的总数。

最佳答案

echo The total Sales for today was %sum:~0,-2%.%sum:~-2% > output2.txt

即,输出sum,除了最后两个字符和一个点,然后是最后两个字符。

关于windows - 在bat文件中编辑字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47071269/

10-15 13:28