POV-Ray : Newsgroups : povray.general : Random numbers and rounding : Re: Random numbers and rounding Server Time
3 Aug 2024 00:25:33 EDT (-0400)
  Re: Random numbers and rounding  
From: Slime
Date: 22 Jun 2004 14:22:16
Message: <40d878d8@news.povray.org>
> Is there any way to round a float to the nearest whole number.

I'm not sure why there's no round() function, but here, this should work:

#macro round(x)
floor(x+0.5)
#end

(floor() is like int() except that it always rounds towards negative
infinity, whereas int() rounds towards zero. The + 0.5 causes the transition
from one integer to another to occur when x passes by something-and-a-half.)

 - Slime
 [ http://www.slimeland.com/ ]


Post a reply to this message

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