如何在PHP FPDF中显示十进制值?

时间:2018-07-30 23:35:25

标签: php decimal fpdf

这是我的代码:

$no=1;
while($item = mysqli_fetch_array($query)){
    $pdf->Cell(10   ,5,$no++,1,0);
    $pdf->Cell(100  ,5,$item['naran'],1,0);
    //add thousand separator using number_format function
    $pdf->Cell(25   ,5,number_format ( $item['folin_faan']),1,0);
    $pdf->Cell(25   ,5,number_format( $item['hamutuk']),1,0);
    $pdf->Cell(34   ,5,number_format( $item['total']),1,1,'R');//end of line
    //accumulate tax and amount
    $tax += $item['hamutuk'];
    $total += $item['total'];

}

应该显示像0.00这样的十进制值

我要显示十进制值的列:

enter image description here

问题:如何精确显示十进制值?

2 个答案:

答案 0 :(得分:0)

如果您希望使用0.00和类似的参数,则您的number_format()参数会消失。

尝试一下:

number_format($item['total'], 2, '.', '');

这显示2个小数,其中.为小数点,(无)为千位分隔符。


完整代码:

$no=1;
while($item = mysqli_fetch_array($query)){
    $pdf->Cell(10, 5, $no++, 1, 0);
    $pdf->Cell(100, 5, $item['naran'], 1, 0);
    // add thousand separator using number_format function
    $pdf->Cell(25, 5, number_format($item['folin_faan'], 2, '.', ''), 1, 0);
    $pdf->Cell(25, 5, number_format($item['hamutuk'], 2, '.', ''), 1, 0);
    $pdf->Cell(34, 5, number_format($item['total'], 2, '.', ''), 1, 1, 'R'); // end of line
    // accumulate tax and amount
    $tax += $item['hamutuk'];
    $total += $item['total'];
}

答案 1 :(得分:0)

您可以使用以下代码:

$this->Cell(30,20,"C$ ".number_format($data->precio_venta,2,'.',','),1,0,'L');

如果花费数千,结果将为C$ 2,500.00,如果花费数百,结果将为C$ 450.00