PHP code example of ayeo / price

1. Go to this page and download the library: Download ayeo/price 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/ */

    

ayeo / price example snippets


$price = new Price(float $nett, float $gross, "GBP")
$price = Price::buildByNett(float $nett, integer $tax, "USD") - returns Price
$price = Price::buildByGross(float $gross, integer $tax, "EUR") - returns Price

$price = Price::buildByNett(100.00, 8, "USD"):

$A = Price::buildByNett(100.00, 8, "USD"):
$B = Price::buildByNett(10.00, 11, "USD"):
$C = $A->add($B);
$C->hasTaxRate(); //returns false

$C->getTax()->getValue(); 

$priceA->add(Price $priceB) - returns Price
$priceA->subtract(Price $priceB) - returns Price
$priceA->multiply(integer $times) - returns Price

$priceA->addGross(float $value) - returns Price
$priceA->subtractGross(float $value) - returns Price

$A = new Price(100.00, 120.00, 'USD');
$B = new Price(10.00, 12.00, 'USD');

$sum = $A->add($B);
$sum->getGross(); //returns 132.00
$A->getGross(); //returns 120.00
$B->getGross(); //returns 12.00

$priceA->isEqual(Price $priceB) - returns bool
$priceA->isLower(Price $priceB) - returns bool
$priceA->isGreater(Price $priceB) - returns bool