fixed a bug in the round function introduced by tkrahn
This commit is contained in:
parent
266f2da4f8
commit
eb296b944c
1 changed files with 11 additions and 4 deletions
|
|
@ -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]);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue