Comma to point decimal separator

Comma to point decimal separator

Anonymous
Not applicable
1,414 Views
10 Replies
Message 1 of 11

Comma to point decimal separator

Anonymous
Not applicable
I need a quick routine (R14 AutoLisp)
to change the decimal separator from comma
(Italian style) to point:

(setq
qta "123,456"
qta2 (itoa (atoi qta))
qta2 (strcat qta2 "." (substr qta (+ 2 (strlen qta2))))
)

123.456

Maybe there is something better.

__________________________________

Marc'Antonio Alessi
(strcat "NOT a " (substr (ver) 5 4) " guru.")
__________________________________
0 Likes
1,415 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable
If you are running the Italian localized version of AutoCAD, doesn't
(getreal) handle comma's instead of periods? If not, I believe this should
be something Autodesk needs to look at.

BTW, this is something I cannot check (no Italian AutoCAD ).

--
R. Robert Bell, MCSE
Xtending the Power
www.acadx.com

"Marc'Antonio Alessi" wrote in message
news:ef28b98.-1@WebX.SaUCah8kaAW...
| I need a quick routine (R14 AutoLisp)
| to change the decimal separator from comma
| (Italian style) to point:
|
| (setq
| qta "123,456"
| qta2 (itoa (atoi qta))
| qta2 (strcat qta2 "." (substr qta (+ 2 (strlen qta2))))
| )
|
| 123.456
|
| Maybe there is something better.
|
| __________________________________
|
| Marc'Antonio Alessi
| (strcat "NOT a " (substr (ver) 5 4) " guru.")
| __________________________________
|
0 Likes
Message 3 of 11

Anonymous
Not applicable
Robert, this is my command line (R15 Italian):

Comando: (getreal "Number: ")
Number: 3
3.0

Comando: (getreal "Number: ")
Number: 3.6
3.6

Comando: (getreal "Number: ")
Number: 3,6

È richiesto un valore numerico. (error)
(numeric value requested)

BTW my question was for general purpose
not only to convert from Italian to English form.
In Italy almost everybody use the decimal point
in drawing (English form) for dimensions or other.

But I have several attribute that somebody wrote
in Italian form.

My little routine works good, I only ask if somebody
have something better to use on a lot of strings.

Thanks for your time.

Best regards.

Ciao, Marco.

"R. Robert Bell" ha scritto nel messaggio
news:ef28b98.0@WebX.SaUCah8kaAW...
> If you are running the Italian localized version of AutoCAD, doesn't
> (getreal) handle comma's instead of periods? If not, I believe this should
> be something Autodesk needs to look at.
>
> BTW, this is something I cannot check (no Italian AutoCAD ).
>
> --
> R. Robert Bell, MCSE
> Xtending the Power
> www.acadx.com
>
0 Likes
Message 4 of 11

Anonymous
Not applicable
Thought that would be what you found. For plain AutoLISP, yours is good (or
you could use this recursion function):

(defun I:Comma->Period (strReal)
(cond
((wcmatch strReal "*#`,*")
(setq
strReal
(strcat
(substr strReal 1 1)
(I:Comma->Period (substr strReal 2))
) ;_ closes strcat
) ;_ closes setq
)
((wcmatch strReal "`,*")
(setq
strReal
(strcat "." (substr strReal 2))
) ;_ closes setq
)
(T strReal)
) ;_ closes cond
) ;_ closes defun

--
R. Robert Bell, MCSE
Xtending the Power
www.acadx.com

"Marc'Antonio Alessi" wrote in message
news:ef28b98.1@WebX.SaUCah8kaAW...
| Robert, this is my command line (R15 Italian):
|
| Comando: (getreal "Number: ")
| Number: 3
| 3.0
|
| Comando: (getreal "Number: ")
| Number: 3.6
| 3.6
|
| Comando: (getreal "Number: ")
| Number: 3,6
|
| È richiesto un valore numerico. (error)
| (numeric value requested)
|
| BTW my question was for general purpose
| not only to convert from Italian to English form.
| In Italy almost everybody use the decimal point
| in drawing (English form) for dimensions or other.
|
| But I have several attribute that somebody wrote
| in Italian form.
|
| My little routine works good, I only ask if somebody
| have something better to use on a lot of strings.
|
| Thanks for your time.
|
| Best regards.
|
| Ciao, Marco.
|
0 Likes
Message 5 of 11

Anonymous
Not applicable
Tanks Robert,

I think this is faster, now I fix for ",n" strings.

(defun Comma2Period ( qta / qta2)
(cond
( (not (setq qta2 (atoi qta))) )
( (zerop qta2) (strcat "." (substr qta 2 )) )
(T (strcat (itoa qta2) "." (substr qta (+ 2 (strlen (itoa qta2))))) )
)
)

Ciao
0 Likes
Message 6 of 11

Anonymous
Not applicable
What! You don't want recursion, for recursion's sake?! What would Michael
say?!

--
R. Robert Bell, MCSE
Xtending the Power
www.acadx.com

"Marc'Antonio Alessi" wrote in message
news:ef28b98.3@WebX.SaUCah8kaAW...
| Tanks Robert,
|
| I think this is faster, now I fix for ",n" strings.
|
| (defun Comma2Period ( qta / qta2)
| (cond
| ( (not (setq qta2 (atoi qta))) )
| ( (zerop qta2) (strcat "." (substr qta 2 )) )
| (T (strcat (itoa qta2) "." (substr qta (+ 2 (strlen (itoa qta2))))) )
| )
| )
|
| Ciao
|
0 Likes
Message 7 of 11

Anonymous
Not applicable
empiric tests:

Comando: test1
2.754

Comando: test2
8.47302

(defun C:TEST1 ( / start stop diff_time)
(setq start (getvar "DATE"))
(repeat 100000
(Comma2Period "123,456")
)
(terpri)
(setq stop (getvar "DATE"))
(terpri)
(setq diff_time (- stop start))
(princ (* 86400.0 (- diff_time (fix diff_time))))
(princ)
)
(defun C:TEST2 ( / qf start stop diff_time)
(setq start (getvar "DATE"))
(repeat 100000
(I:Comma->Period "123,456")
)
(terpri)
(setq stop (getvar "DATE"))
(terpri)
(setq diff_time (- stop start))
(princ (* 86400.0 (- diff_time (fix diff_time))))
(princ)
)
(defun Comma2Period ( qta / qta2)
(cond
( (not (setq qta2 (atoi qta))) )
( (zerop qta2) (strcat "." (substr qta 2 )) )
(T (strcat (itoa qta2) "." (substr qta (+ 2 (strlen (itoa qta2))))) )
)
)
(defun I:Comma->Period (strReal)
(cond
((wcmatch strReal "*#`,*")
(setq
strReal
(strcat
(substr strReal 1 1)
(I:Comma->Period (substr strReal 2))
) ;_ closes strcat
) ;_ closes setq
)
((wcmatch strReal "`,*")
(setq
strReal
(strcat "." (substr strReal 2))
) ;_ closes setq
)
(T strReal)
) ;_ closes cond
)

"R. Robert Bell" ha scritto nel messaggio
news:ef28b98.4@WebX.SaUCah8kaAW...
> What! You don't want recursion, for recursion's sake?! What would Michael
> say?!
0 Likes
Message 8 of 11

Anonymous
Not applicable
I found an error with "0,123" (zero leading string),
now the only problem is in strings with more than
one zero before the comma ("00.123") but I think
this is not a real case.

(defun Comma2Period ( qta / qta2)
(cond
( (not (setq qta2 (atoi qta))) )
( (zerop qta2)
(if (= "0" (substr qta 1 1)) (strcat "." (substr qta 3 )) (strcat "."
(substr qta 2 )))
)
(T (strcat (itoa qta2) "." (substr qta (+ 2 (strlen (itoa qta2))))) )
)
)

Marco
0 Likes
Message 9 of 11

Anonymous
Not applicable
Guess my recursive function might work after all? 00,123 is not a problem
for it. Sometimes faster isn't better (don't let Bill Gates know that!) Your
function is nice, though.

--
R. Robert Bell, MCSE
Xtending the Power
www.acadx.com

"Marc'Antonio Alessi" wrote in message
news:ef28b98.6@WebX.SaUCah8kaAW...
| I found an error with "0,123" (zero leading string),
| now the only problem is in strings with more than
| one zero before the comma ("00.123") but I think
| this is not a real case.
0 Likes
Message 10 of 11

Anonymous
Not applicable
> Sometimes faster isn't better (don't let Bill Gates know that!)

Must I think that "Mr. Bill" code is fast?
Or the best?
Or best and fast?
Or ...

Ciao, Marco.
0 Likes
Message 11 of 11

Anonymous
Not applicable
Or the closest to a monopoly...

--
R. Robert Bell, MCSE
Xtending the Power
www.acadx.com

"Marc'Antonio Alessi" wrote in message
news:ef28b98.8@WebX.SaUCah8kaAW...
| > Sometimes faster isn't better (don't let Bill Gates know that!)
|
| Must I think that "Mr. Bill" code is fast?
| Or the best?
| Or best and fast?
| Or ...
|
| Ciao, Marco.
|
0 Likes