Jorge Almeida [JA], on Tuesday, July 12, 2005 at 08:26 (+0100 (WEST))
typed:
JA> Is there some way to really round a number to a given number of digits
JA> after the point?
JA> For example (1 digit):
JA> 12.3 --> 12.3
JA> 12.34 --> 12.3
JA> 12.35 --> 12.4
JA> 12.349 --> 12.3
JA> sprintf doesn't seem to work:
JA> $ perl -e '$a=11.45; $a=sprintf("%.1f", $a); print $a;'
JA> 11.4
Hm, first I thoug, that could not be a problem, when I run:
my @numbers = (12.3, 12.34, 12.35, 12.349, 11.45, 11.46);
for (@numbers) {
printf "$_ => %.1f\n", $_;
}
I get strange with 11.45 too. So...
we should read:
perldoc -f round
interesting part:
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.
--
How do you protect mail on web? I use http://www.2pu.net
[Yo'momma so ugly she practices birth control by leaving the lights on!]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>