Come faccio ad arrotondare un numero intero??
Ecco il mio caso arrotondando ai 50 superiori o inferiori:
147 deve diventare 150
1327 deve diventare 1350
1320 deve diventare 1300
Come faccio ad arrotondare un numero intero??
Ecco il mio caso arrotondando ai 50 superiori o inferiori:
147 deve diventare 150
1327 deve diventare 1350
1320 deve diventare 1300
Poi chiami:Codice PHP:
function roundTo($number, $base) {
$i = $number / $base;
if (abs($i - (int) $i) <= 0.5)
return (int) $i * $base;
else
return (int)($i+1) * $base;
}
A naso dovrebbe funzionare, non l'ho provata.Codice PHP:
$result = roundTo($number, 150);
echo round(147/50)*50;
echo round(1327/50)*50;
echo round(1320/50)*50;
Ehm si, alla fine mi sono fatto il round a mano :\
Nicola sei un grande... metodo semplice ed efficace... grazie!!