package Common::RSMath;

use lib '/app/tools/common/lib';
use Common::Assert;

use strict;
use Exporter;

use vars qw(@ISA @EXPORT @EXPORT_OK);

@EXPORT    = qw();
@EXPORT_OK = qw(round);
@ISA       = 'Exporter';

sub round {
    my ( $n, $places ) = @_;

    ( $places, undef ) = split( /\./, $places );
    assert( $places >= 0 );

    my $factor = 10**( $places || 0 );
    my ( $left, $right ) = split( /\./, $n * $factor );

    if ($right) {
        my @allChars = split( //, $right );
        if ( scalar @allChars > 0 ) {
            if ( $allChars[0] >= 5 ) {
                ( $n < 0 ) ? $left-- : $left++;
            }
        }
    }

    return ( $left / $factor );
}

###
1;    # Play nicely.
###
