1.5553 - 1.5552 # 1 point 1.5553 - 1.55 # 53 points (your sub will fail with this) 1.56 - 1.55 # 1 point? 100 points? (insoluble from data alone) #### sub points { my ($was,$is,$exp) = @_; unless ($exp) { $was =~ m/\.(\d+)$/; my $x = $1 ? length($1) : 0; $is =~ m/\.(\d+)$/; my $y = $1 ? length($1) : 0; $exp = $x > $y ? $x : $y; } print "($exp) $was => $is\t"; $exp = 10**$exp; my $dif = $is*$exp - $was*$exp; # add correction factor to allow int to round correctly # also ensures that FP "error" such as 4.999999 ends up as +5 $dif += $dif < 0 ? -0.5 : +0.5; return sprintf "%+d", $dif; } print points(1.5553,1.5552), $/; print points(1.55,1.5553 ), $/; print points(1.55,1.56), $/; print points(1.55,1.56,4), $/; print points(0.9984,0.998), $/; __DATA__ (4) 1.5553 => 1.5552 -1 (4) 1.55 => 1.5553 +53 (2) 1.55 => 1.56 +1 (4) 1.55 => 1.56 +100 (4) 0.9984 => 0.998 -4