home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pcmagazi / 1992 / 13 / div.bat < prev    next >
DOS Batch File  |  1991-11-22  |  2KB  |  87 lines

  1. echo off
  2. cls
  3. if %1!==! goto instr
  4. echo Calculations are in PROGRESS!
  5. strings /p~ decpos2 = find ~~%2~.
  6. if not %decpos2%==0 goto havdec2
  7. set num2=%2
  8. goto getone
  9. :havdec2
  10. strings decpos2 = sub %decpos2%,1
  11. strings num2 = left %2,%decpos2%
  12. strings decpos2 = add %decpos2%,2
  13. strings dec2 = mid %2,%decpos2%,128
  14. strings decpl2 = length %dec2%
  15. set num2=%num2%%dec2%
  16. :getone
  17. strings /p~ decpos1 = find ~~%1~.
  18. if not %decpos1%==0 goto havdec1
  19. set num1=%1
  20. goto chkdpl
  21. :havdec1
  22. strings decpos1 = sub %decpos1%,1
  23. strings num1 = left %1,%decpos1%
  24. strings decpos1 = add %decpos1%,2
  25. strings dec1 = mid %1,%decpos1%,128
  26. strings decpl1 = length %dec1%
  27. set num1=%num1%%dec1%
  28. :chkdpl
  29. strings sub %num1%,%num2% > nul
  30. if not errorlevel 1 goto addk
  31. strings num1 = mul %num1%,10
  32. strings decpl1 = add %decpl1%,1
  33. goto chkdpl
  34. :addk
  35. strings #decpl = sub %decpl1%,%decpl2% > nul
  36. if errorlevel 1 goto mult
  37. if not %#decpl%==0 if not %#decpl%==1 if not %#decpl%==2 goto divide
  38. :mult
  39. strings num1 = mul %num1%,10
  40. strings decpl1 = add %decpl1%,1
  41. goto addk
  42. :divide
  43. strings answer = div %num1%,%num2%
  44. :getlen
  45. strings len = length %answer%
  46. strings sub %len%,%#decpl% > nul
  47. if not errorlevel 1 goto getint
  48. set answer=0%answer%
  49. goto getlen
  50. :getint
  51. strings intlen = sub %len%,%#decpl%
  52. strings int = left %answer%,%intlen%
  53. strings decml = right %answer%,%#decpl%
  54. if %int%!==! set int=0
  55. set answer=%int%.%decml%
  56. echo %1 / %2 = %answer%
  57. set answer=
  58. set int=
  59. set decml=
  60. set intlen=
  61. set num1=
  62. set num2=
  63. set #decpl=
  64. set decpl1=
  65. set decpl2=
  66. set dec1=
  67. set dec2=
  68. set decpos1=
  69. set decpos2=
  70. set len=
  71. goto end
  72. :instr
  73. echo / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
  74. echo.
  75. echo        Enter the numbers after %0; dividend followed by divisor,
  76. echo.
  77. echo                         such as DIV 20.5 .25
  78. echo.
  79. echo        The quotient will have at least 3 places of decimal (default).
  80. echo        If you wish more, add zeros in the decimal place of the dividend.
  81. echo.
  82. echo  / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
  83. :end
  84. echo.
  85. echo.
  86. :end
  87.