- Perl ›
- builtin functions ›
- here
ceil function - round up the fractional part
You can use the ceil function to round up the decimal point.
use POSIX 'ceil'; $ret = ceil $num;
Example
This is an example using the ceil function.
use strict; use warnings; use POSIX 'ceil'; my $num1 = 1.5; my $num2 = -1.5; print "(1) Round up the decimal point.\n"; my $num1_ceil = ceil $num1; my $num2_ceil = ceil $num2; print "Round up $num1: $num1_ceil\n"; print "Round up $num2: $num2_ceil\n\n";