my $sign = ""; if ($example < 0) { $example = -$example; $sign = "-"; } $tret = sprintf("rounded float: %s%7.5f", $sign, $example);