• 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: String to real conversion question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: String to real conversion question


  • Subject: RE: String to real conversion question
  • From: Scott Babcock <email@hidden>
  • Date: Tue, 4 May 2010 06:00:37 +0000
  • Thread-topic: String to real conversion question

If your strings will always use the period as the decimal separator, the 'run script' OSAX event is your friend:

    set theReal to (run script "0.25")

This won't handle strings that include thousands separators, though. If you need to handle the general case, you'll need to deal with locale-specific separators.
If you need efficiency, 'run script' also has the typical OSAX overhead. In this case, you can use 'number' coercion by pre-processing to normalize the separators.

-----Original Message-----
Date: Sun, 2 May 2010 18:51:03 +0200
From: Bert Groeneveld <email@hidden>
Subject: Re: String to real conversion question
To: Applescript Users <email@hidden>
Message-ID:
	<email@hidden>
Content-Type: text/plain; charset="us-ascii"

Hi Michelle,
That will never occur in my specific situation. But thanks for the tip
anyway.
Bert.

On 2 mei 2010 (17), at 18:43, Michelle Steiner wrote:

> On May 2, 2010, at 9:35 AM, Bert Groeneveld wrote:
>
>> -- Don't know if this is the smartest way for a find and replace
>> action, but here's how I worked around it . . .
>>
>> set x to "0.25" -- string
>> set y to "4" -- string
>>
>> if x contains "." then
>> 	set AppleScript's text item delimiters to "."
>> 	set x to every text item of x as list
>> 	set AppleScript's text item delimiters to ","
>> 	set x to x as string
>> 	set AppleScript's text item delimiters to ""
>> end if
>> set z to x * y --> 1.0
>
> But what if x is greater than one thousand, and is formatted
> something like "2,341.25"?
>
> -- Michelle
>
> --
> A great Idea!  That's what we need--a great idea.
>  --Pseudolus, (A Funny Thing Happened on the way to the forum)

 _______________________________________________
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

  • Follow-Ups:
    • Re: String to real conversion question
      • From: Yvan KOENIG <email@hidden>
  • Prev by Date: VideoEncoder/CommandLine/Programmer
  • Next by Date: Re: Date question with weeknumber
  • Previous by thread: Re: String to real conversion question
  • Next by thread: Re: String to real conversion question
  • Index(es):
    • Date
    • Thread