1
0
Fork 0
mirror of https://github.com/archtechx/money.git synced 2025-12-12 03:14:03 +00:00

Merge pull request #14 from gauravmak/master

Readme updates and code cleanup
This commit is contained in:
Samuel Štancl 2022-03-08 20:54:12 +01:00 committed by GitHub
commit c7ccaa42c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 12 deletions

View file

@ -49,12 +49,12 @@ $money->value(); // 4500
$money = money(1500); // $15.00; default currency
$money = money(1500, 'EUR'); // 15.00 €
$money = money(2000, new USD); // $20.00
$money = money(3000, CZK::class); // 20 Kč
$money = money(3000, CZK::class); // 30 Kč
// Using decimals
$money = Money::fromDecimal(15.00, 'EUR'); // 15.00 €
$money = Money::fromDecimal(20.00, new USD); // $20.00
$money = Money::fromDecimal(30.00, CZK::class); // 20 Kč
$money = Money::fromDecimal(30.00, CZK::class); // 30 Kč
```
### Arithmetics
@ -112,16 +112,16 @@ money(100, USD::class)->equals(money(200, CZK::class));
// Assuming CZK is 25:1 USD
// ✅ true
money(100, USD::class)->equals(money(100, USD::class));
money(100, USD::class)->is(money(100, USD::class));
// ❌ false: different monetary value
money(100, USD::class)->equals(money(200, USD::class));
money(100, USD::class)->is(money(200, USD::class));
// ❌ false: different currency
money(100, USD::class)->equals(money(2500, CZK::class));
money(100, USD::class)->is(money(2500, CZK::class));
// ❌ false: different currency AND monetary value
money(100, USD::class)->equals(money(200, CZK::class));
money(100, USD::class)->is(money(200, CZK::class));
```
### Adding fees
@ -221,6 +221,8 @@ To work with the registered currencies, use the bound `CurrencyManager` instance
### Creating a currency
This package provides only USD currency by default.
You can create a currency using one of the multiple supported syntaxes.
```php
// anonymous Currency object
@ -412,7 +414,7 @@ For the Czech Crown (CZK), the display decimals will be `0`, but the math decima
For the inverse of what was just explained above, you can use the `rawFormatted()` method. This returns the formatted value, **but uses the math decimals for the display decimals**. Meaning, the value in the example above will be displayed including cents:
```php
money(123456, new CZK)->formatted(); // 1 235,56 Kč
money(123456, new CZK)->rawFormatted(); // 1 235,56 Kč
```
This is mostly useful for currencies like the Czech Crown which generally don't use cents, but **can** use them in specific cases.

View file

@ -43,5 +43,10 @@
}
},
"minimum-stability": "dev",
"prefer-stable": true
"prefer-stable": true,
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
}
}
}

View file

@ -1,6 +1,5 @@
<?php
use ArchTech\Money\CurrencyManager;
use ArchTech\Money\Currencies\USD;
use ArchTech\Money\Currency;
use ArchTech\Money\Money;

View file

@ -1,6 +1,5 @@
<?php
use ArchTech\Money\CurrencyManager;
use ArchTech\Money\Tests\Currencies\CZK;
test('money is rounded to its math decimals after each operation', function () {

View file

@ -1,8 +1,6 @@
<?php
use ArchTech\Money\CurrencyManager;
use ArchTech\Money\Currencies\USD;
use ArchTech\Money\Currency;
use ArchTech\Money\Money;
use ArchTech\Money\Tests\Currencies\CZK;
use ArchTech\Money\Tests\Currencies\EUR;