Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: How do I round up a number?

by Daddio (Chaplain)
on Apr 01, 2001 at 19:53 UTC ( [id://68835]=note: print w/replies, xml ) Need Help??


in reply to How do I round up a number?

Another non-module way is to use sprintf.
@num = (6, 5.3, 8.5, 9.5000000001, 3.84, 4.51); foreach $num (@num) { print qq{original: $num\n}; $new = sprintf "%.0f\n",$num; print qq{new: $new}; }
will produce
original: 6 new: 6 original: 5.3 new: 5 original: 8.5 new: 8 original: 9.5000000001 new: 10 original: 3.84 new: 4 original: 4.51 new: 5
Not quite right for the 8.5, but it is close for the rest, and that can be compared differently.

Originally posted as a Categorized Answer.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://68835]
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 2026-03-06 11:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.