Search code examples
phpfpdf

Percentage Calculation in PHP in FPDF


I am looking to make a percentage calculation on an FPDF based invoice template which contains $total (e.g 1000) and a number value $percentage (e.g. 20)

Ideally I would like this to display as discount

$pdf->Cell(100, 5, 'Discount' .$discountresult. '', 0, 'L');

How to achieve this? Some advice would be appreciated.


Solution

  • Like this:

    $total = 1000;
    $percentage = 20;
    
    $discountResult =  $total - (($percentage / 100) * $total);
    
    $pdf->Cell(100, 5, 'Discount' . $discountResult, 0, 'L');