Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Best way to round a number.

by Perlbotics (Abbot)
on Oct 26, 2012 at 21:07 UTC ( #1001137=note: print w/ replies, xml ) Need Help??


in reply to Best way to round a number.

use strict; use warnings; sub round5 { my $num = shift; return $num+2 - ($num+2) % 5; # <------ TIMTOWTDI ;-) } for (0..10) { printf "%3d -> %3d %3d -> %3d\n", $_, round5($_), -$_, round5(-$_); } __DATA__ 0 -> 0 0 -> 0 1 -> 0 -1 -> 0 2 -> 0 -2 -> 0 3 -> 5 -3 -> -5 4 -> 5 -4 -> -5 5 -> 5 -5 -> -5 6 -> 5 -6 -> -5 7 -> 5 -7 -> -5 8 -> 10 -8 -> -10 9 -> 10 -9 -> -10 10 -> 10 -10 -> -10


Comment on Re: Best way to round a number.
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (14)
As of 2014-09-30 12:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (368 votes), past polls