Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

How do I round a floating point number?

by vroom (His Eminence)
on Feb 02, 2000 at 00:15 UTC ( [id://2671] : CUFP . print w/replies, xml ) Need Help??

You need to use sprintf or printf.
$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 +);
You might also want to take a look at floor and ceil

Replies are listed 'Best First'.