function roundInt($num) {
if((int)$num !== $num)
return $num; // non int's simply get returned
$num = (string)$num;
return $num[0] . str_repeat('0', strlen($num)-1);
}
EDIT: Alternate method:
function roundInt($num) {
$len = strlen((string)abs($num)) - 1;
return floor($num / pow(10, $len)) * pow(10, $len);
}
Note that this handles negative numbers in a way that you may not desire, e.g. roundInt(-35) will return -40. If you'd rather it return -30, then it becomes a bit more complicated:
function roundInt($num) {
$len = strlen((string)abs($num)) - 1;
if($num >= 0)
return floor($num / pow(10, $len)) * pow(10, $len);
else
return ceil($num / pow(10, $len)) * pow(10, $len);
}