On Tue, 12 Jul 2005, Ing. Branislav Gerzo wrote:
what about this:
my @numbers = (12.3, 12.34, 12.35, 12.349, 11.45, 11.46);
for (@numbers) {
print "$_ => " . round($_, 1) . "\n";
}
sub round {
my ($number,$decimals) = @_;
return substr($number+("0." . "0" x $decimals . "5"),
0, $decimals+length(int($number))+1);
}
Yes! :):):)
I still get
12.4499999999999999999 --> 12.5
but this is acceptable.
Many thanks,
Jorge Almeida
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>