在乘法php中舍入2位小数不是舍入

时间:2016-05-23 17:39:46

标签: php

我来找你寻找答案,我有一张桌子,我正在计算税收领域,每0.16乘以1个变量,但我希望它只有2个小数,而不是10或4或3,我试着用圆形( )并且使用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;
}

1 个答案:

答案 0 :(得分:0)

如果您只想围绕一个数字,那么这就是解决方案:

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