Re: Same code gives different answers in 2 different scripts
Re: Same code gives different answers in 2 different scripts
- Subject: Re: Same code gives different answers in 2 different scripts
- From: Shane Stanley <email@hidden>
- Date: Wed, 03 Jun 2009 12:33:59 +1000
- Thread-topic: Same code gives different answers in 2 different scripts
On 3/6/09 11:42 AM, "Chris Page" <email@hidden> wrote:
> On Jun 2, 2009, at 4:56 PM, Shane Stanley wrote:
>
> On 3/6/09 8:52 AM, "Chris Page" <email@hidden> wrote:
>
> to findRound of num given numDecimals:n
> set x to 10 ^ n
> return (round (num * x)) / x
> end findRound
>
> set rounded_height to findRound of 3 given numDecimals:0
> --> 3.0
>
> I guess what Shane is trying to say is that the script doesn¹t know how to
> handle numDecimals when it¹s zero.
Sort of. But:
to findRound of num given numDecimals:n
set x to 10 ^ n
return (round (num * x)) / x
end findRound
set rounded_height to findRound of 3 given numDecimals:5
--> 3.0
What I'm really trying to say is that adding the ability to set a minimum or
maximum number of decimals would make the round command a lot more useful.
The multiply-the-divide method is a pain because of all the potential
gotchas.
And who knows, if we asked for the result as text, we might one day get
"0.001" rather than "1.0E+1". A person's allowed to dream...
--
Shane Stanley <email@hidden>
AppleScript Pro Sessions <http://scriptingmatters.com/aspro>
_______________________________________________
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