home *** CD-ROM | disk | FTP | other *** search
-
- rem 4DOS provides an internal function, @int[], but not a way
- rem to get the fractional part of a number. Here's a tool.
- rem This is also a simple illustration of modifying an environment
- rem variable whose name is passed in.
-
- rem The key lesson in this example is the use and modification of
- rem the VALUE of a variable given its NAME in %1.
-
- rem This .btm is meant to be CALLed from another batch file.
- rem
- if "%1" == "" .or. "%[%1]" == "" goto help
- rem ! !
- rem ! The VALUE of variable "name"
- rem The NAME of a variable
-
-
- rem The following sets the given variable to the fractional part.
- rem Note the function nesting.
-
- rem The third argument of @substr is omitted, referring to the rest
- rem of the string by default [4DOS 4.0 enhancement]
-
- rem The length of the integer portion is used as the offset into the
- rem string to begin and extract the fraction portion.
-
- set %1=%@substr[%[%1],%@len[%@int[%[%1]]]]
- :exit
- quit 0
-
- :help
- rem
- rem Note the use of the name of the command the user typed, even
- rem though this .btm file may have been renamed.
- rem
- echo Usage: %@name[%0] var
- echo.
- echo var = Any environment variable whose value is the input
- echo New value returned in var, replacing original value.
- echo New value is the fraction portion of a floating point value.
- echo Example: set foo=12.345
- echo %@name[%0] foo
- echo set foo
- echo .345
- quit 4