POV-Ray : Newsgroups : povray.general : Round to nearest integer : Re: Round to nearest integer Server Time
19 Apr 2024 10:56:30 EDT (-0400)
  Re: Round to nearest integer  
From: Mike Horvath
Date: 27 May 2021 09:32:07
Message: <60af9f57$1@news.povray.org>
On 5/27/2021 9:17 AM, clipka wrote:
> Am 27.05.2021 um 13:31 schrieb Mike Horvath:
>>> Has someone written a macro that rounds a float to the nearest 
>>> integer? Thanks!
> ...
>> Or, to the nearest multiple of n, where n is any number.
> 
> try `floor(FOO / N + 0.5) * N`.

I found this on web and adapted it to POV:

   #macro round(number, base)
     (((number + base/2) / base) * base)
   #end

Not sure which of the two is preferable.


Mike


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.