Scusa ma perchè non provi prima di fare certe domande.Originariamente inviato da clockworkorange
senti, e se un numero è 1,599 mi scrive 1,59 oppure 1,60 perchè approssima automaticamente?
grazie
$numero = 1.599;
$numero = number_format($numero,2,',','');
echo $numero; // restituisce 1,60
Una domanda intelligente sarebbe stata: uso number_format ma mi restituisce 1,60 mentre io vorrei ottenere 1,59. come posso fare?
Se è quello il tuo problema:
function truncate ($num, $digits = 0) {
$shift = pow(10 , $digits);
return ((floor($num * $shift)) / $shift);
}
$numero_arrot = truncate ($numero,2);
echo $numero_arrot; // e ti restituisce 1,59.
edit: meglio,ti restituisce 1.59.
A questo punto applichi number_format se lo vuoi visualizzato con la virgola.