2016-05-23 47 views
0

我來找你找答案,我有一張表,我計算的稅收場每乘以一個變量乘以1個變量,但我希望它只有2個小數,而不是10或4或3,我正在嘗試與round()和number_format(),但沒有工作,必須有一些我做錯了,它是如何假設我需要這樣做?第2輪小數在一個乘法PHP不是四捨五入

我顯示的代碼

$html .= '<tr> 
    <td>'.escape($r->tecnologia).'</td> 
    <td>'.escape($r->normaespecificacion).'</td> 
    <td><img src="functions/'.escape($r->foto).'"></td> 
    <td>'.escape($r->marca).'</td> 
    <td>'.escape($r->modelo).'</td> 
    <td>'.escape($r->descripcion).'</td> 
    <td>$'.escape($r->preciounitario).'</td> 
    <td>$'.escape($r->number_format(preciounitario*0.16,2)).'</td> //this is the one with the error 
    <td>$'.escape($r->instalacion).'</td> 
    <td>$'.escape($r->totalcosto).'</td> 
    <td>'.escape($r->garantia).'</td> 
    <td>'.$listNum[$i].'</td> 
    </tr>'; 
    $totalV += $listNum[$i]*$r->totalcosto; 
    $i = $i+1; 
} 
+1

什麼是'$ r'?它實際上有一個'number_format'方法嗎?那是什麼代碼? –

+0

嘗試'number_format($ r-> preciounitario * 0.16,2))'VTC作爲錯字 – RiggsFolly

+0

number_format($ r-> preciounitario * 0.16,2))不起作用 –

回答

0

如果你只是把一個數字,然後在這裏是解決方案:

<?php 
    $number = 1353.234242; 
    $rounded = (float)sprintf('%.2f', $number); 
    echo $rounded; // will display 1353.23