1,代码没有优化,所以速度。。。100行转换实测耗时2.46妙,汗一个先
2,要求所有文本内只存在科学记数的内容,不含其他内容。
3,批处理放在同一目录下,新生成的文本将放到test子目录中。
4,e后的数字允许范围为000到999
5,小数部分最多保留16位(按楼主的要求)
6,数字小于0.0000000000000001时将被近似为0.0000000000000001- @echo off&setlocal enabledelayedexpansion
- if not exist "test\" md test
- for %%z in (*.txt) do (
- for /f "usebackq tokens=1,2* delims=e." %%a in ("%%z") do (
- set a=%%a&set b=%%b&set c=%%c
- set d=!c:~1!
- for %%d in (0 0) do if !d:~0^,1!==0 set d=!d:~1!
- if !a:~0^,1!==- set n=-&set a=!a:~1!
- if !a:~0^,1!==0 (echo.0) else (
- set m=!a!!b!
- if !c:~0^,1!==+ (
- if !d! lss 16 (
- set/a d+=1
- for %%d in (!d!) do set m=!m:~0,%%d!.!m:~%%d!
- ) else (
- set/a a=d-16
- for /l %%d in (1,1,!a!) do set z=!z!0
- set m=!m!!z!
- )
- ) else (
- set/a a=d-1
- for /l %%d in (1,1,!a!) do set z=!z!0
- set m=0.!z!!m!&set m=!m:~0,18!
- )
- echo.!m!|find ".">nul 2>nul&&call:f !m!
- echo.!n!!m!
- )
- set n=&set z=))>test\%%z
- exit
- :f
- set f=%1
- if %f%==0.0000000000000000 set f=0.0000000000000001
- for /f "tokens=1,2 delims=." %%a in ("%f%") do set a=%%a&set b=.%%b
- :g
- if not "!b:~%g%,1!"=="" set/a g+=1&goto:g
- for /l %%a in (1,1,%g%) do if not !b:~-%%a^,1!==0 (
- set/a h=%%a-1
- if not !h!==0 for %%b in (!h!) do set "b=!b:~0,-%%b!"
- goto:e)
- :e
- set m=%a%%b%&set g=
- if %m:~-1%==. set m=%m:~0,-1%
复制代码
[ 本帖最后由 hanyeguxing 于 2010-5-2 03:37 编辑 ] |