fixed a bug in the round function introduced by tkrahn

This commit is contained in:
JT Smith 2003-02-15 18:00:37 +00:00
parent 266f2da4f8
commit eb296b944c

View file

@ -283,23 +283,30 @@ sub randomizeHash {
#-------------------------------------------------------------------
=head2 round ( real )
=head2 round ( float [, significantDigits ] )
Returns an integer after rounding a real number.
Returns an integer after rounding a floating point number.
=over
=item real
=item float
Any floating point number.
=item significantDigits
The number of digits to leave after the decimal point. Defaults to 0.
NOTE: If you set this higher than 0 then you'll get back another floating point number rather than an integer.
=back
=cut
sub round {
return int( $_ < 0 ? $_ - 0.5 : $_ + 0.5 );
my $significantDigits = $_[1] || 0;
return sprintf(('%.'.$significantDigits.'f'), $_[0]);
}
#-------------------------------------------------------------------