Hieronder een stukje van mijn Vlisp Console.
_$ (rtos 1234.56789)
"1234.5679"
_$ (atof "1234.56789")
1234.57
_$ (atof "1234,56789")
1234.0
_$
Zoals jullie zien wordt het getal afgerond.
Als ik dat wilde gebruikte ik wel fix.
Waar/hoe kan ik dit voorkomen? :?
$ (atof "1234,56789")
1234.0
hier gooit de komma roet in het eten.
De afrondings nauwkeurigheid is afhankelijks van je nauwkeurigheids instellingen bij units
bij rtos kan je de nauwkeurigheid opgeven
Command: (rtos 1234.5678901 2 10)
"1234.5678901"
uit de help van 2008
Converts a number into a string
(rtos number [mode [precision]])
The rtos function returns a string that is the representation of number according to the settings of mode, precision, and the system variables UNITMODE, DIMZIN, LUNITS, and LUPREC.
Arguments
number
A number.
mode
An integer specifying the linear units mode. The mode corresponds to the values allowed for the LUNITS AutoCAD system variable. The mode can be one of the following numbers:
1 Scientific
2 Decimal
3 Engineering (feet and decimal inches)
4 Architectural (feet and fractional inches)
5 Fractional
precision
An integer specifying the precision.
The mode and precision arguments correspond to the system variables LUNITS and LUPREC. If you omit the arguments, rtos uses the current settings of LUNITS and LUPREC.
Return Values
A string. The UNITMODE system variable affects the returned string when engineering, architectural, or fractional units are selected (mode values 3, 4, or 5).
Examples
Set variable x:
Command: (setq x 17.5)
17.5
Convert the value of x to a string in scientific format, with a precision of 4:
Command: (setq fmtval (rtos x 1 4))
"1.7500E+01"
Convert the value of x to a string in decimal format, with 2 decimal places:
Command: (setq fmtval (rtos x 2 2))
"17.50"
Convert the value of x to a string in engineering format, with a precision of 2:
Command: (setq fmtval (rtos x 3 2))
"1'-5.50\""
Convert the value of x to a string in architectural format:
Command: (setq fmtval (rtos x 4 2))
"1'-5 1/2\""
Convert the value of x to a string in fractional format:
Command: (setq fmtval (rtos x 5 2))
"17 1/2"
Setting UNITMODE to 1 causes units to be displayed as entered. This affects the values returned by rtos for engineering, architectural, and fractional formats, as shown in the following examples:
Command: (setvar "unitmode" 1)
1
Command: (setq fmtval (rtos x 3 2))
"1'5.50\""
Command: (setq fmtval (rtos x 4 2))
"1'5-1/2\""
Command: (setq fmtval (rtos x 5 2))
"17-1/2"
Beste Joop,
De waarde die een functie geeft (de prompt) kan verschillend van zijn waarde zijn. :nigoe:
Waarom ze dat zo gemaakt hebben, dat weet ik met mijn blonde kopje niet. :oops:
Misschien om de uitvoer eenvoudig te houden.
(defun c:test( / Xs Xv ~zin prec)
(setq ~zin (getvar "DIMZIN") prec 12)
(textscr)
(setvar "DIMZIN" 0)
(princ "\n********uitvoer bij Dimzin op 0 **********")
(setq xS "444.123456789")
(Princ "\nDe string Xs is:\n")
(princ Xs)
(setq Xv (atof Xs))
(Princ "\nString Xs omgezet naar een getal Xv geeft:\n")
(princ Xv)
(Princ "\nHet getal Xv weer omgezet naar een string geeft:\n")
(princ (rtos Xv 2 prec))
(Princ "\nBij het getal Xv 0.000001 optellen geeft:\n")
(princ (+ Xv 0.000001))
(Princ "\nDe waarde van Xv+0.000001 omgezet naar een string geeft:\n")
(princ (rtos (+ Xv 0.000001) 2 prec))
(setvar "DIMZIN" 8)
(princ "\n********uitvoer bij Dimzin op 8 **********")
(Princ "\nDe string Xs is:\n")
(princ Xs)
(setq Xv (atof Xs))
(Princ "\nString Xs omgezet naar een getal Xv geeft:\n")
(princ Xv)
(Princ "\nHet getal Xv weer omgezet naar een string geeft:\n")
(princ (rtos Xv 2 prec))
(Princ "\nBij het getal Xv 0.000001 optellen geeft:\n")
(princ (+ Xv 0.000001))
(Princ "\nDe waarde van Xv+0.000001 omgezet naar een string geeft:\n")
(princ (rtos (+ Xv 0.000001) 2 prec))
(setvar "DIMZIN" ~zin)
(princ)
)
In mijn ogen niks geks mee, dus geen ghost whisperer inschakelen.
Met vriendelijke groet, HofCAD CSI.
PS Lijkt een beetje op dit onderwerp http://www.cadsite.be/smf/index.php/topic,2677.0.html
Bedankt Bart,
Zoals je kan zien zijn dit alemaal 2 decimalen of engelse maten.
Ik heb de getallen op 6 decimalen uitgelezen en geconverteerd naar text.
Ales prima.
Aleen het teruzetten werkt niet(?).
Bedankt HofCAD CSI.
Ik probeer het morgen uit.
Het heeft even geduurd en ik ben er nog niet uit.
Ik blijf het vreemd vinden dat er maar 2 en/of 3 decimalen verschijnen.
Maar ik kan er wel mee werken, aleen de controle is lastier.