#! 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