1. Go to this page and download the library: Download wsw/money 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/ */
wsw / money example snippets
php
use WSW\Money\Currency;
use WSW\Money\Money;
$money = new Money('1500.9999', new Currency('USD'));
php
use WSW\Money\Currency;
use WSW\Money\Money;
$money = new Money("1500.00", new Currency("USD"));
$money2 = new Money("1500.00", new Currency("USD"));
$money3 = new Money("1000.00", new Currency("USD"));
var_dump($money->equals($money2)); // bool(true)
var_dump($money->equals($money3)); // bool(false)
php
use WSW\Money\Currency;
use WSW\Money\Money;
$money = new Money('100', new Currency('USD'));
$addValue = new Money('50', new Currency('USD'));
$newMoney = $money->add($addValue);
echo $newMoney->getAmount(); // (string) 150.000000
echo $newMoney->getTruncate(); // (string) 150.00
echo $newMoney->getRound(); // (string) 150.00
echo $newMoney->getFormat(); // (string) 150,00
echo $newMoney; // (string) 150,00
php
use WSW\Money\Currency;
use WSW\Money\Money;
use WSW\Money\Percentage;
$money = new Money('100', new Currency('USD'));
$percent = new Percentage("75%");
$newMoney = $money->addPercent($percent);
echo $newMoney->getAmount(); // (string) 175.000000
echo $newMoney->getTruncate(); // (string) 175.00
echo $newMoney->getRound(); // (string) 175.00
echo $newMoney->getFormat(); // (string) 175,00
echo $newMoney; // (string) 175,00
php
use WSW\Money\Currency;
use WSW\Money\Money;
$money = new Money('100', new Currency('USD'));
$subValue = new Money('60.75', new Currency('USD'));
$newMoney = $money->sub($subValue);
echo $newMoney->getAmount(); // (string) 39.250000
echo $newMoney->getTruncate(); // (string) 39.25
echo $newMoney->getRound(); // (string) 39.25
echo $newMoney->getFormat(); // (string) 39,25
echo $newMoney; // (string) 39,25
php
use WSW\Money\Currency;
use WSW\Money\Money;
use WSW\Money\Percentage;
$money = new Money('100', new Currency('USD'));
$percent = new Percentage("75%");
$newMoney = $money->subPercent($percent);
echo $newMoney->getAmount(); // (string) 25.000000
echo $newMoney->getTruncate(); // (string) 25.00
echo $newMoney->getRound(); // (string) 25.00
echo $newMoney->getFormat(); // (string) 25,00
echo $newMoney; // (string) 25,00
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.