sub round { my $self = shift; my $rnd = $self->{precision}; my $number = shift; return(sprintf("%0.${rnd}f", $number)); };; print round( {precision=>3}, 1.23456 );; 1.235 print round( {precision=>3}, 1 );; 1.000 print round( {precision=>3} );; Use of uninitialized value $number in sprintf at ... 0.000