• 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: Arthur J Knapp <email@hidden>
  • Date: Fri, 22 Mar 2002 16:36:49 -0500

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

>> 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

;-)

You are the only scripter I know that can write code like this and
still have it be thought of as "easy to understand". :)

Nigel has mentioned in the past that he does not like handlers that
consist of a single line of code. It is fortunate for us that AppleScript
requires so many linebreaks to compile, otherwise Nigel's contributions
would all look like this:

tell n div x * x to if it < n then set r to it + x else set r to it


{ Arthur J. Knapp, of <http://www.STELLARViSIONs.com>
<mailto:email@hidden>
try
<http://www.esglabs.com/>
on error number -128
end try
}
_______________________________________________
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: unable to do batch operations
  • Next by Date: Re: search and replace
  • Previous by thread: Re: Rounding
  • Next by thread: Re: Rounding
  • Index(es):
    • Date
    • Thread