Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: rounding to nearest

by rob_au (Abbot)
on Mar 22, 2003 at 09:21 UTC ( [id://245114]=note: print w/replies, xml ) Need Help??


in reply to rounding to nearest

How about the following?

sub round { my ( $price, $round ) = @_; return int(( $price / $round ) + 0.5 ) * $round; } print round( 418, 10 ), "\n";

The round subroutine takes two parameters, the number to be rounded and the nearest value to which you want it to be rounded to.

 

perl -le 'print+unpack("N",pack("B32","00000000000000000000001001000001"))'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-24 16:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found