Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: rounding to nearest

by dakkar (Hermit)
on Mar 22, 2003 at 09:18 UTC ( #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? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2022-05-29 12:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (101 votes). Check out past polls.

    Notices?