Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

RE: Round a Number to Any Place

by tye (Sage)
on Aug 29, 2000 at 23:57 UTC ( [id://30198]=note: print w/replies, xml ) Need Help??


in reply to Round a Number to Any Place

Nice work. Here are, I think, two improvements:

sub round { my( $num, $prec )= @_; return int( $num/$prec + 0.5 - ($num<0) ) * $prec; }

This is slightly simpler and rounds negative numbers properly.

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
RE (2): Round a Number to Any Place
by nuance (Hermit) on Aug 30, 2000 at 00:09 UTC
    We've done this number rounding thing before. Have a look at the thread following this node to see why the 0.5 thing isn't quite exact.

    Nuance

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-24 08:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found