• 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: Rounding
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rounding


  • Subject: Re: Rounding
  • From: Nigel Garvey <email@hidden>
  • Date: Thu, 21 Mar 2002 11:12:01 +0000

Arthur J Knapp wrote on Wed, 20 Mar 2002 16:40:03 -0500:

>> From: Nigel Garvey <email@hidden>
>
>> Rob Jorgensen wrote on Tue, 19 Mar 2002 20:47:10 -0500:
>
>>> So, how do I round 14 to 15, or 16 to 20? Does anyone care to share a
>>> handler which addresses this?
>
>
>> As long as you're only dealing with positive whole numbers, this should
>> be enough:
>>
>> on rndUpTo5(n)
>> (n + 4) div 5 * 5
>
> But Nigel...
>
> What if the universe were to stop expanding and to begin its slow
>return to the big bang. In that case, is it not possible that time
>itself might start to move backwards, thereby breaking any script
>that assumes that seconds will always be positive whole numbers ???

Hmmm, yes. I hadn't thought of that. In that case, it would probably be
better to round away from zero rather than up, in order to maintain - er
- backward compatability. ;-)

> (where is my medication?) ;-)

That's easy when time's running backwards. Simply regurgitate it into the
bottle and see where you put it. :-)

> Am I correct in assuming that your handler can be generalized as this: ?
>
> on rndUpToX(n, x)
> return (n + (x - 1)) div x * x

As long as you're only dealing with positive whole numbers, yes. :-)
(More correctly, it only works when n and x are both positive and the
difference between n and the previous multiple of x is greater than or
equal to 1.)

For more general use:

on rndUpToX(n, x)
tell n div x * x
if it < n then return it + x
it
end tell
end rndUpToX

NG
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Input key
  • Next by Date: Re: AS manuals
  • Previous by thread: Re: Rounding
  • Next by thread: Re: Rounding
  • Index(es):
    • Date
    • Thread