[PLUG] Perl round-up

Ed Sawicki ed at alcpress.com
Tue Aug 13 20:39:32 UTC 2002


On Tue, 2002-08-13 at 10:27, Rich Shepard wrote:
> On 13 Aug 2002, Ed Sawicki wrote:
> 
> > I need to round a floating point number up to the next integer, regardless
> > of what the fractional part is. Here's my first attempt:
> > 
> > if (int($score) != $score) {
> >     $score = int($score) + 1;
> > }
> 
> Ed,
> 
>   Back in the Old Days, before BCD and large-integer math, we just added 0.5
> to the float value, then rounded. I believe that the standard C library
> rounds up; truncate would "round" down.

I wanted something different. I wanted to round up if there
was a fractional part, regardless of the value of the fractional
part. My code (in Perl) did that but there's a POSIX function
called ceil() that did it without the additional test:

$score = ceil($score);

Ed 





More information about the PLUG mailing list