Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Best way to round a number.

by Perlbotics (Chancellor)
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1001137]
help
Chatterbox?
[erix]: my app (google, really) makes that 1530 km...
[Eily]: google tells me 1662 km ...
[LanX]: Nancy? Somewhere near Metz ...
[Eily]: must be km farenheit or something :P
[Eily]: wow, don't say that in Nancy LanX :P
[erix]: maybe you used the car routes, I used the walking routes
[Eily]: there's a rivalry between the two cities, so defining one in terms of the other might not be well received
[Eily]: erix well I did click on the walking icon
LanX giggles!
[LanX]: Eily I'm duing this constantly with people from rival cities ...MUCHO fun!

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2017-12-13 15:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (369 votes). Check out past polls.

    Notices?