|Function Syntax||(LM:rtos <real> <units> <prec>)|
|real||Real||Number to be converted to a string.|
|units||Integer||An integer specifying the linear units mode, as per the in-built rtos function.|
|prec||Integer||An integer specifying the precision, as per the in-built rtos function.|
|String||The result of evaluating the rtos function with the DIMZIN System Variable set to 0.|
The result of evaluating the AutoLISP rtos function is dependent upon the current value of the DIMZIN System Variable, in addition to the values of both the LUNITS & LUPREC System Variables. This subtle dependency can lead to inconsistencies arising when programs are used across drafting environments in which these System Variables differ in value.
Although the units and precision of the string returned by the rtos function are dependent upon the values of the LUNITS & LUPREC System Variables respectively, these variables only take effect when the optional unit and precision parameters are omitted from the rtos function call and hence this potential inconsistency can be averted.
However, the effect of the setting of the DIMZIN System Variable on the display of leading or trailing zeros in the returned string cannot be controlled by the parameters supplied to the rtos function.
Consequently, due to variation in the DIMZIN System Variable across drafting environments, the rtos function can sometimes produce undesired and occasionally troublesome results, even when both arguments have been specified.
Here are some examples to illustrate this potential inconsistency:
DIMZIN = 0 _$ (rtos 0.234 2 2) "0.23" DIMZIN = 4 _$ (rtos 0.234 2 2) ".23"
DIMZIN = 0 _$ (rtos -0.23 2 3) "-0.230" DIMZIN = 12 _$ (rtos -0.23 2 3) "-.23"
That last example may also cause problems with applications using the read function as a method of converting strings to other data types.
The following fairly simple wrapper function for the rtos function will always return the result of evaluating the rtos function with the DIMZIN System Variable set to 0, thus eradicating any incongruency between drafting environments.
;; rtos wrapper - Lee Mac ;; A wrapper for the rtos function to negate the effect of DIMZIN (defun LM:rtos ( real units prec / dimzin result ) (setq dimzin (getvar 'dimzin)) (setvar 'dimzin 0) (setq result (vl-catch-all-apply 'rtos (list real units prec))) (setvar 'dimzin dimzin) (if (not (vl-catch-all-error-p result)) result ) )
To demonstrate, using the earlier examples:
DIMZIN = 0 _$ (LM:rtos 0.234 2 2) "0.23" DIMZIN = 4 _$ (LM:rtos 0.234 2 2) "0.23"
DIMZIN = 0 _$ (LM:rtos -0.23 2 3) "-0.230" DIMZIN = 12 _$ (LM:rtos -0.23 2 3) "-0.230"