Re: String to sum
Re: String to sum
- Subject: Re: String to sum
- From: Mr Tea <email@hidden>
- Date: Wed, 13 Oct 2004 00:18:02 +0100
This from Martin Orpen - dated 12/10/04 9·04 pm:
> set n to do shell script "echo \"scale=8 \n" & (biglist as string) & "\" | bc
> -s2"
Er, yes, but what does this mean? What is scale=8¹? what is | bc s2¹?
Perhaps it does what¹s needed here but I like to understand what¹s going on
in my scripts, rather than just pasting in magic code¹ that works because
it works. I'm not completely averse to the use of shell script capabilities
in AppleScript, but don't want to learn a load of stuff that duplicates what
AS can do already.
The handler I had knocked up, which, as I noted previously, was more
efficient than 'run script' was simply this:
on calcthis(calc, n1, n2)
if calc is "+" then set rslt to n1 + n2
if calc is "-" then set rslt to n1 - n2
if calc is "/" then set rslt to n1 / n2
if calc is "*" then set rslt to n1 * n2
return rslt
end calcthis
Is there any real advantage in using 'else' here, instead of a bunch of
plain old 'if's?
That's just a side question, really, because all of the above is made
redundant by the 'evalformula' command in the Satimage Osax (thanks,
Emmanuel :-) )
set n1 to "5"
set n2 to "4.1"
set calc to "+"
evalformula (n1 & calc & n2) as string
--> "9.1"
Nick
pp Mr Tea
--
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden