You can do it with spritnf:
my $rounded = sprintf("%.3f", 1/3);
This isn't this sprintf
's purpose, but it does the job.
If you want just three digits after the dot, you can do it with math computations:
my $num = 1/3;
my $part;
$part = $1 if $num=~/^\d+\.(\d{3})/;
print "3 digits after dot: $part\n" if defined $part;