Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: rounding to nearest

by dakkar (Hermit)
on Mar 22, 2003 at 09:18 UTC ( [id://245113]=note: print w/replies, xml ) Need Help??


in reply to rounding to nearest

$nearest=10; $price=int(($price+$nearest/2)/$nearest)*$nearest;

This is parametric on the "granularity"

UPDATE: and it also works if $nearest is less than 1 (say you want to round to the nearest 0.5)

-- 
        dakkar - Mobilis in mobile

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-25 20:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found