in reply to decimal isn't truncating

A 'percentage' is a ratio that is compared to 100.

You are creating a ratio that is based on 1, not 100.

my $ratio_correct = $number_correct / $total_number; my $percent_correct = $number_correct * 100 / $total_number;

It may also be that you're confused by what '%.2f' does in the context of (s)printf ... From perldoc for sprintf:

.number "precision": digits after decimal point for floating-point, max length for string, minimum length for integer

If you're trying to truncate in perl, I'd recommend using '%d', not '%.f' or '%.0f', so it won't round up.