Jorge Almeida [JA], on Tuesday, July 12, 2005 at 09:23 (+0100 (WEST))
thoughtfully wrote the following:
>> Rounding in financial applications can have serious implications, and
>> the rounding method used should be specified precisely. In these cases,
>> it probably pays not to trust whichever system rounding is being used by
>> Perl, but to instead implement the rounding function you need yourself.
JA> Yes, I read that yesterday. Hope there is an easier solution...
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);
}
--
How do you protect mail on web? I use http://www.2pu.net
["Exciting is hardly the word I would choose" - C3P0]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>