PHP code example of dansketic / laravel-money

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

    

dansketic / laravel-money example snippets


'providers' => array(
    ...
    ...
    ClickNow\Money\MoneyServiceProvider::class,
),

use ClickNow\Money\Money;

echo Money::BRL(500); // 'R$ 5,00' unconverted
echo new Money(500, new Currency('BRL')); // 'R$ 5,00' unconverted
echo Money::BRL(500, true); // 'R$ 500,00' converted
echo new Money(500, new Currency('BRL'), true); // 'R$ 500,00' converted

var $m1 = Money::BRL(500);
var $m2 = Money::BRL(500);

$m1->getCurrency();
$m1->isSameCurrency($m2);
$m1->compare($m2);
$m1->equals($m2);
$m1->greaterThan($m2);
$m1->greaterThanOrEqual($m2);
$m1->lessThan($m2);
$m1->lessThanOrEqual($m2);
$m1->convert(Currency::USD, 3.5);
$m1->add($m2);
$m1->subtract($m2);
$m1->multiply(2);
$m1->divide(2);
$m1->allocate([1, 1, 1]);
$m1->isZero();
$m1->isPositive();
$m1->isNegative();
$m1->format();

money(500, 'BRL')
currency('BRL')

@money(500, 'BRL')
@currency('BRL')