zaokrąglenie przy wyliczaniu ceny netto

<?php

declare(strict_types=1);

namespace Module\Service\Domain\WriteModel\Service\Calculator;

use Module\Service\Domain\WriteModel\Model\Price;

final class TaxCalculator
{
    public static function calculateNetPrice(int $grossPrice, int $tax): int
    {
        if ($tax <= 0 || $grossPrice <= 0) {
            return $grossPrice;
        }

        $taxPercent = $tax / Price::ONE_HUNDRED_PERCENT;
        $netPrice = ($grossPrice / ($taxPercent + 1));

        return (int) round($netPrice);
    }
}
Price::ONE_HUNDRED_PERCENT = 10000

 

Komentarze wyłączone