[英]round 2 decimals in a multiplication php is not rounding
我來找你找答案,我有一張桌子,我正在計算稅額,每0.16乘以1變量,但我希望它只有2個小數,而不是10或4或3,我正在嘗試使用round()和number_format()但不能正常工作,一定是我做錯了什么,我該怎么辦呢?
我正在顯示代碼
$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;
}
如果您只是想舍入一個數字,那么這里是解決方案:
<?php
$number = 1353.234242;
$rounded = (float)sprintf('%.2f', $number);
echo $rounded; // will display 1353.23
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.