Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

My contribution to the fray.

Update:Removed spurious hash left over from an earlier attempt.

#! perl -slw use strict; sub categorise { use POSIX qw[log10]; my $n = shift; die 'Argument less than 1' unless $n > 0; return 5 if $n <= 5; return 10 if $n <=10; return 5 * int( $n / 5 + 1 ) if $n <= 100; my $scale = int( log10( $n ) ); return (0+"1e$scale") * 0.25 * ( 1 + int( ( $n / (0+"1e$scale") ) / 0.25 ) ); } my $t = 2.4; for( 1 .. 20 ) { $t *= 1.55; printf "%5d : %5d\n", int($t), categorise( int( $t ) ); } =pod comment Expose for a more thorough and randomised test. printf "%5d : %5d\n", int($_), categorise( int( $_ ) ) for 1..15, ( map{ 10* ($_ + rand) } 2 .. 9 ), ( map{ 100* ($_ + rand) } 1 .. 9 ), ( map{ 1000* ($_ + rand) } 1 .. 9 ); =cut __END__ P:\>270920 3 : 5 5 : 5 8 : 10 13 : 15 21 : 25 33 : 35 51 : 55 79 : 80 123 : 125 192 : 200 297 : 300 461 : 475 715 : 725 1108 : 1250 1718 : 1750 2663 : 2750 4129 : 4250 6400 : 6500 9920 : 10000 15376 : 17500

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller



In reply to Re: Rounding values upwards on an arbitrary basis by BrowserUk
in thread Rounding values upwards on an arbitrary basis by ibanix

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-25 15:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found