mirror of
https://github.com/archtechx/money.git
synced 2025-12-12 03:14:03 +00:00
text: readme updates and code cleanup
This commit is contained in:
parent
1b34e3f4c2
commit
dce1269799
5 changed files with 15 additions and 12 deletions
16
README.md
16
README.md
|
|
@ -49,12 +49,12 @@ $money->value(); // 4500
|
||||||
$money = money(1500); // $15.00; default currency
|
$money = money(1500); // $15.00; default currency
|
||||||
$money = money(1500, 'EUR'); // 15.00 €
|
$money = money(1500, 'EUR'); // 15.00 €
|
||||||
$money = money(2000, new USD); // $20.00
|
$money = money(2000, new USD); // $20.00
|
||||||
$money = money(3000, CZK::class); // 20 Kč
|
$money = money(3000, CZK::class); // 30 Kč
|
||||||
|
|
||||||
// Using decimals
|
// Using decimals
|
||||||
$money = Money::fromDecimal(15.00, 'EUR'); // 15.00 €
|
$money = Money::fromDecimal(15.00, 'EUR'); // 15.00 €
|
||||||
$money = Money::fromDecimal(20.00, new USD); // $20.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
|
### Arithmetics
|
||||||
|
|
@ -112,16 +112,16 @@ money(100, USD::class)->equals(money(200, CZK::class));
|
||||||
// Assuming CZK is 25:1 USD
|
// Assuming CZK is 25:1 USD
|
||||||
|
|
||||||
// ✅ true
|
// ✅ true
|
||||||
money(100, USD::class)->equals(money(100, USD::class));
|
money(100, USD::class)->is(money(100, USD::class));
|
||||||
|
|
||||||
// ❌ false: different monetary value
|
// ❌ 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
|
// ❌ 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
|
// ❌ 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
|
### Adding fees
|
||||||
|
|
@ -221,6 +221,8 @@ To work with the registered currencies, use the bound `CurrencyManager` instance
|
||||||
|
|
||||||
### Creating a currency
|
### Creating a currency
|
||||||
|
|
||||||
|
This package provides only USD currency by default.
|
||||||
|
|
||||||
You can create a currency using one of the multiple supported syntaxes.
|
You can create a currency using one of the multiple supported syntaxes.
|
||||||
```php
|
```php
|
||||||
// anonymous Currency object
|
// 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:
|
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
|
```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.
|
This is mostly useful for currencies like the Czech Crown which generally don't use cents, but **can** use them in specific cases.
|
||||||
|
|
|
||||||
|
|
@ -43,5 +43,10 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
"prefer-stable": true
|
"prefer-stable": true,
|
||||||
|
"config": {
|
||||||
|
"allow-plugins": {
|
||||||
|
"pestphp/pest-plugin": true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use ArchTech\Money\CurrencyManager;
|
|
||||||
use ArchTech\Money\Currencies\USD;
|
use ArchTech\Money\Currencies\USD;
|
||||||
use ArchTech\Money\Currency;
|
use ArchTech\Money\Currency;
|
||||||
use ArchTech\Money\Money;
|
use ArchTech\Money\Money;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use ArchTech\Money\CurrencyManager;
|
|
||||||
use ArchTech\Money\Tests\Currencies\CZK;
|
use ArchTech\Money\Tests\Currencies\CZK;
|
||||||
|
|
||||||
test('money is rounded to its math decimals after each operation', function () {
|
test('money is rounded to its math decimals after each operation', function () {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use ArchTech\Money\CurrencyManager;
|
|
||||||
use ArchTech\Money\Currencies\USD;
|
use ArchTech\Money\Currencies\USD;
|
||||||
use ArchTech\Money\Currency;
|
|
||||||
use ArchTech\Money\Money;
|
use ArchTech\Money\Money;
|
||||||
use ArchTech\Money\Tests\Currencies\CZK;
|
use ArchTech\Money\Tests\Currencies\CZK;
|
||||||
use ArchTech\Money\Tests\Currencies\EUR;
|
use ArchTech\Money\Tests\Currencies\EUR;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue