Perlで切り上げ(ceil)と切り捨て(floor)を使う

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#!/usr/bin/perl
use strict;
use warnings;
use POSIX;
my @vars = (1, 0.999, 0.9, 0.1, -0.1, -0.9, -0.999, -1);
foreach my $var (@vars) {
print "Target is $var\n";
print "ceil  : ", ceil($var), "\n";
print "floor : ", floor($var), "\n";
print "int   : ", int $var, "\n";
}

Comments

comments powered by Disqus