Re: Basic casting question
Re: Basic casting question
- Subject: Re: Basic casting question
- From: KOENIG Yvan <email@hidden>
- Date: Sun, 1 Mar 2009 19:40:48 +0100
Le 1 mars 2009 à 19:24:22, Pinus a écrit :
Hi everyone,
I'm surprisingly stuck by a cast I try to do from a string to a real.
I have a function that returns something like "339.700012"
I want this result to be casted as a real (set myResult to myResult
as real) but I always get the same error :
"can't make "339.700012" into type real"
Is there something I missed regarding casting in AS ?
Thanks.
Stéphane _
My guess is that you are in a country where the decimal separator is
not the period but the comma.
--[SCRIPT]
my string2real("339.700012")
on string2real(s)
if character 2 of (0.5 as text) is "." then
if s contains "," then set s to my replace(s, ",", ".")
else
if s contains "." then set s to my replace(s, ".", ",")
end if
return s as real
end string2real
on replace(t, d1, d2)
local l
set AppleScript's text item delimiters to d1
set l to text items of t
set AppleScript's text item delimiters to d2
set t to l as text
set AppleScript's text item delimiters to ""
return t
end replace
--[/SCRIPT]
Yvan KOENIG (from FRANCE dimanche 1 mars 2009 19:39:50)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden