No commas!
- - - - - - - - - - begin screen capture Win2000 - - - - - - - - - -
C:\cmd>zformat2 1234567890987654321234567890987654321 . 1,234,567,890,987,654,321,234,567,890,987,654,321
C:\cmd>rlist C:\cmd\TEST\zFORMAT2.cmd
=====begin C:\cmd\TEST\zFORMAT2.cmd ====================
01. @echo off
02. ::
03. :: inserts commas in number of any length
04. ::
05. :: examples: 12345678 becomes 12,345,678
06. :: $12345678.99 becomes $12,345,678.99
07. :: 12345678.00172 becomes 12,345,678.00172
08. ::
09. :: result is returned in environment variable %~n0
10. ::
11. :: to DISPLAY the result, enter "." as the second parameter
12. ::
13. if {%1} NEQ {} (if {%1} NEQ {?} (if {%1} NEQ {/?}^
14. (if /i {%1} NEQ {HELP} ( goto :begin ))))
15. call XHELP %~f0
16. goto :EOF
17. :begin
18. setlocal
19. set S001=%1
20.
21. :: remove leading dollar sign, if any
22. if %S001:~0,1%==$ (
23. set currency=yes
24. set S001=%S001:~1%
25. )
26.
27. :: remove fractional portion, if any
28. for /f "tokens=1,2 delims=." %%a in ("%S001%") do set fraction=%%b
29. if defined fraction call set S001=%%S001:.%fraction%=%%%
30.
31. set S002=%S001%
32. set length=0
33. :zsize
34. set /a length+=1
35. set S002=%S002:~1%
36. if defined S002 goto :zsize
37. set /a ctr=-1
38. set out=
39. for /l %%a in (%length%,-1,0) do call :digit %%a
40. if "%out:~0,1%"=="," set out=%out:~1%
41. if defined fraction set out=%out%.%fraction%
42. if defined currency set out=$%out%
43. if "%2"=="." echo %out%
44. endlocal&set %~n0=%out%&goto :EOF
45.
46. :digit
47. set pos=%1
48. set /a ctr+=1
49. if %ctr% EQU 3 set comma=,
50. call set digit=%%S001:~%pos%,1%%%
51. call set out=%comma%%digit%%out%%
52. if defined comma (
53. set comma=
54. set ctr=0
55. )
56. goto :EOF
=====end C:\cmd\TEST\zFORMAT2.cmd ====================
- - - - - - - - - - end screen capture Win2000 - - - - - - - - - -
--
Phil Robyn
Univ. of California, Berkeley
u n z i p m y a d d r e s s t o s e n d e - m a i l
|