Thanks for your reply. I've got the majority of this code working now, however for some reason, when I round certain numbers up or down I get the same number from the list, for example: [code]function my_round_down($n,$a){ sort($a); $out=$a[0]; for ($i=0;$i<count($a);$i++) { if ($a[$i]<$n){ $out=$a[$i]; } } return $out; } function my_round($n,$a) { sort($a); $out=$a[0]; $p=abs($n-$out); for ($i=1;$i<count($a);$i++) { if (abs($a[$i]-$n)<=$p) { $out=$a[$i]; $p=abs($n-$out); } } return $out; } $number = 6987; //Or whatever number has been submitted from a form $pre=array(5000,10000,15000,25000,50000,75000,100000,125000,200000,300000,400000,500000, 1500000); $new_number_rounded_down = my_round_down($number,$pre); $new_number_rounded_up = my_round($number,$pre); echo $new_number_rounded_down; //Gives 5000 echo $new_number_rounded_up; //Gives 5000 (should give 10000)[/code] If I swap $number for something like 92000 it gives the correct lower and higher rounded numbers. I've had a look but not sure what i'm doing wrong. Any ideas? Thanks