Re: [quickie] Rounding up to next multiple

"Bernie Cosell" <[email protected]>
Newsgroups gmane.comp.lang.perl.fun
Organization Fantasy Farm Fibers
Message-ID <3F3A0ACC.17419.B8BC38@localhost>
On 13 Aug 2003 at 14:46, Paul Makepeace wrote:

> This isn't really perl, but it might be mildly fun for a few seconds:
> 
>   $len += $page_size - $len % $page_size if $len % $page_size;
> 
> Any way of doing this in a single arithmetic expression, without the if?

How about:

   $len = int(($len + $page_size-1) / $page_size) ;

/Bernie\
-- 
Bernie Cosell                     Fantasy Farm Fibers
mailto:[email protected]     Pearisburg, VA
    -->  Too many people, too few sheep  <--
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.