Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: How do I print/round a number to a given number of decimal places?

by vroom (His Eminence)
on Jan 11, 2000 at 01:22 UTC ( [id://1947]=note: print w/replies, xml ) Need Help??


in reply to How do I print/round a number to a given number of decimal places?

Probably the easiest way is to use printf/sprintf:

$unrounded = 0.66666; printf "$unrounded rounded to 3 decimal places is %.3f\n", $unrounded; $rounded = sprintf "%.2f", $a; # rounded to 2 decimal places (0.67)
  • Comment on Re: How do I print/round a number to a given number of decimal places?
  • Download Code

Replies are listed 'Best First'.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1947]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-18 22:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found