• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Basic casting question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Basic casting question


  • Subject: Re: Basic casting question
  • From: KOENIG Yvan <email@hidden>
  • Date: Mon, 2 Mar 2009 20:58:37 +0100


Le 2 mars 2009 à 19:58:16, CYB 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

I think that the problem is where the coercion is happening set r to "339.700012" r as real -->> 339.700012 But if I try class of r as real -->> Can’t make text into type real. If you try class of (r as real) -->> Real

So maybe you just need some parenthesis in some place..

No, the problem is linked to the decimal separator.

When the operating system is set to use the period as decimal separator,
casting a string as real requires that in this string, the decimals are separated from the INT part by a period.


When the operating system is set to use the comma as decimal separator,
casting a string as real requires that in this string, the decimals are separated from the INT part by a comma.


If you want to build a string which may be coerced worldwide you must use:

--[SCRIPT]
set deci to character 2 of (.5 as text)
set theString to "98765" & deci &"4321"
set theNumber to theString as real
--[/SCRIPT]

If you aren't the one building the string, you must normalize it as I described in my message:
De : email@hidden
Objet : Rép : Basic casting question
Date : 1 mars 2009 19:40:48 HNEC


Yvan KOENIG (from FRANCE lundi 2 mars 2009 20:58:32)


_______________________________________________ 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
References: 
 >Re: Basic casting question (From: CYB <email@hidden>)

  • Prev by Date: Re: Basic casting question
  • Next by Date: RE: Basic casting question
  • Previous by thread: Re: Basic casting question
  • Next by thread: RE: Basic casting question
  • Index(es):
    • Date
    • Thread