PHP code example of dnkmdg / price-tidy

1. Go to this page and download the library: Download dnkmdg/price-tidy library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dnkmdg / price-tidy example snippets


use Dnkmdg\PriceTidy\PriceTidy;
use Dnkmdg\PriceTidy\Strategies\RoundUpToNearestIntegerStrategy;

$priceTidy = new PriceTidy(10.5, 1.25, new RoundUpToNearestIntegerStrategy());
echo $priceTidy->priceIncVat; // Output: 14

use Dnkmdg\PriceTidy\PriceTidy;
use Dnkmdg\PriceTidy\Strategies\RoundUpToNearestTenStrategy;

$priceTidy = new PriceTidy(10.5, 1.25, new RoundUpToNearestTenStrategy());
echo $priceTidy->priceIncVat; // Output: 20

namespace Dnkmdg\PriceTidy\Strategies;

class RoundToNearestFiveStrategy extends RoundingStrategy
{
    public function round(float $value): float
    {
        return round($value / 5) * 5;
    }
}

use Dnkmdg\PriceTidy\PriceTidy;
use Dnkmdg\PriceTidy\Strategies\RoundToNearestFiveStrategy;

$priceTidy = new PriceTidy(10.5, 1.25, new RoundToNearestFiveStrategy());
echo $priceTidy->priceIncVat; // Output will be 15