PHP code example of cyrtolat / laravel-money
1. Go to this page and download the library: Download cyrtolat/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/ */
cyrtolat / laravel-money example snippets )
[comment]: <> ('locale' => 'en_US')
[comment]: <> ()
[comment]: <> ('storage' => \Cyrtolat\Money\Storages\IsoCurrencyStorage::class)
[comment]: <> ()
[comment]: <> ('serializer' => \Cyrtolat\Money\Serializers\MajorMoneySerializer::class)
[comment]: <> ()
[comment]: <> ('formatter' => \Cyrtolat\Money\Formatters\DecimalMoneyFormatter::class)
[comment]: <> ()
[comment]: <> (use \Cyrtolat\Money\Facades\Money;)
[comment]: <> (# указание значения в "минорном" и "мажорном" стилях)
[comment]: <> ($money = Money::of(150.23, 'RUB'); // 150.23 RUB)
[comment]: <> ($money = Money::ofMinor(15023, 'RUB'); // 150.23 RUB)
[comment]: <> (# также можно передавать и объект Currency вместо кода)
[comment]: <> ($currency = Money::getCurrencyOf('RUB');)
[comment]: <> ($money = Money::of(150.23, $currency);)
[comment]: <> ($money = Money::ofMinor(15023, $currency);)
[comment]: <> ()
[comment]: <> (use \Cyrtolat\Money\Facades\Money;)
[comment]: <> ($money_1 = Money::of(150.23, 'RUB'); // 150.23 RUB)
[comment]: <> ($money_2 = Money::of(320.88, 'RUB'); // 320.88 RUB)
[comment]: <> ($money = $money_1->plus($money_2); // $money_1 + $money_2)
[comment]: <> ($money = $money_1->minus($money_2); // $money_1 - $money_2)
[comment]: <> ($money = $money_1->multiplyBy(2.3); // $money_1 * 2.3)
[comment]: <> ($money = $money_1->divideBy(4); // $money_1 / 4)
[comment]: <> ($money = $money_1->round(); // 150.00 RUB)
[comment]: <> ($bool = $money_1->gt($money_2); // $money_1 > $money_2)
[comment]: <> ($bool = $money_1->gte($money_2); // $money_1 >= $money_2)
[comment]: <> ($bool = $money_1->lt($money_2); // $money_1 < $money_2)
[comment]: <> ($bool = $money_1->lte($money_2); // $money_1 <= $money_2)
[comment]: <> ($bool = $money_1->equals($money_2); // $money_1 == $money_2)
[comment]: <> ($bool = $money_1->hasSameAmount($money_2); // false)
[comment]: <> ($bool = $money_1->hasSameCurrency($money_2); // true)
[comment]: <> ()
[comment]: <> (use \Cyrtolat\Money\Facades\Money;)
[comment]: <> ($money = Money::of(150.23, 'RUB');)
[comment]: <> (# I have: 150.23 RUB)
[comment]: <> (echo "I have: " . $money->render();)
[comment]: <> (echo "I have: " . $money;)
[comment]: <> (bash
php artisan vendor:publish --provider="Cyrtolat\Money\Providers\MoneyServiceProvider"