$unrounded=0.66666; $rounded=sprintf("%.2f",$a) #$rounded is rounded to 2 decimal places and is equal to 0.67 printf("$unrounded rounded to 3 decimal places is %.3f\n",$unrounded);