Jump to content

Decimal places using RTOS or should I use something else ?


MojaPana

Recommended Posts

Hello, I have a small problem with decimal places.

 

I have written a small program to write an altitude and draw small figure.

 

Example :

when "z" value is 3.0931456... it turns into 3.093 (OK, 3 decimal places)

But if "z" value is 2.0000000... it turns into 2 (NOT OK, 0 decimal places), Must be 10.000

 

Using this command:

(setq alti (rtos alta 2 3))

alt.PNG

Link to comment
Share on other sites

when Z = a string:

(setq alti "2.00000000") <= given value
(setq alti (strcat (substr alti 1 (vl-string-position (ascii ".") alti)) (substr alti (+ (vl-string-position (ascii ".") alti) 1) 4)))
returns: "2.000"

 

when Z = a real:

(setq alti 2.00000000) <= given value
(setq alti (rtos alti))(setq alti (strcat (substr alti 1 (vl-string-position (ascii ".") alti)) (substr alti (+ (vl-string-position (ascii ".") alti) 1) 4)))
returns: "2.000"

Link to comment
Share on other sites

; =========================================================================================== ;
; Konwertuje liczbe na lancuch tekstowy / Converts number to a string                         ;
;  Val  [REAL/INT] - liczba do konwersji / conversion number                                  ;
;  Unit [iNT/nil]  - jednostki wyjsciowe / output unit                                        ;
;                    nil = domyslne / default | (getvar "LUNITS")                             ;
;                    1   = naukowe / scientific                                               ;
;                    2   = dziesietne / decimal                                               ;
;                    3   = inzynierskie / engineering                                         ;
;                    4   = architektoniczne / architectural                                   ;
;                    5   = ulamkowe / fractional                                              ;
;  Prec [iNT/nil]  - INT = liczba miejsc po przecinku / number of decimal places              ;
;                    nil = domyslna / default | (getvar "LUPREC")                             ;
; ------------------------------------------------------------------------------------------- ;
; (cd:CON_Real2Str 12 2 4)                                                                    ;
; =========================================================================================== ;
(defun cd:CON_Real2Str (Val Unit Prec / DMZ res)
 (setq DMZ (getvar "DIMZIN"))
 (setvar "DIMZIN"
   (if (not (member (getvar "LUNITS") (list 4 5)))
     (logand DMZ (~ ) 0
   )
 )
 (setq res
   (rtos
     Val
     (if (and Unit (member Unit (list 1 2 3 4 5))) 
       Unit
       (getvar "LUNITS")
     )
     (if Prec Prec (getvar "LUPREC"))
   )
 )
 (setvar "DIMZIN" DMZ)
 res
)

From: CADPL-Pack-v1.lsp

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...