The POSIX module contains functions called ceil and floor which return the first integer greater or less than a given number.
--#!/usr/bin/perl -w use strict; use POSIX qw(ceil floor); my @numbers = qw(1 1.2 1.5 1.7 -1.2 -1.5 -1.7); foreach (@numbers) { printf("x: %.1f: ceil(x): %d floor(x) %d\n", $_, ceil($_), floor($_)); }
"Perl makes the fun jobs fun
and the boring jobs bearable" - me
In reply to Re: Rounding without int() or printf()
by davorg
in thread Rounding without int() or printf()
by Mandor
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |