Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Perl
Perl Misc
Rounding up to the next .5
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="anno4000, post: 4837266"] You can base one on the other. Rounding to the nearest half can be seen as multiplying by two, then rounding to the nearest integer, then dividing by two again. Generalizing, you get sub round_to_multiple { my ( $x, $factor) = @_; $factor*sprintf '%.0f', $x/$factor; } which can be used as for ( map 0.1*$_, 0 .. 10 ) { printf "%s -> %s\n", $_, round_to_multiple( $_, 1/2); } Anno [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Perl
Perl Misc
Rounding up to the next .5
Top