API reference / Quittio \ Core \ Support
Amount
final class in quittio/core
Quittio\Core\Support\Amount · Source
Factory for monetary amounts.
EN 16931 allows at most two decimals for every amount, independent of the currency's minor unit. All amounts therefore use a fixed scale of 2.
Constants#
| Constant | Value | Description |
|---|---|---|
SCALE | 2 |
Methods#
| Method | Description |
|---|---|
::context() | |
::currency() | Currency for a code. Codes unknown to ISO 4217 are accepted, so that invalid input leads to a validation finding (BR-CL-04) instead of an exception. |
::format() | Amount as string with exactly two decimals (e.g. "1234.50"). |
::fromDecimal() | |
::of() | Creates an amount. Values with more than two decimals are rejected unless $round is true. |
::ofNullable() | |
::zero() |
context()#
public static function context(): CustomContext- Returns
Brick\Money\Context\CustomContext
currency()#
public static function currency(string $code): CurrencyCurrency for a code. Codes unknown to ISO 4217 are accepted, so that invalid input leads to a validation finding (BR-CL-04) instead of an exception.
| Parameter | Type | Description |
|---|---|---|
$code | string |
- Returns
Brick\Money\Currency
format()#
public static function format(Money $money): stringAmount as string with exactly two decimals (e.g. "1234.50").
| Parameter | Type | Description |
|---|---|---|
$money | Brick\Money\Money |
- Returns
string
fromDecimal()#
public static function fromDecimal(BigDecimal $value, string $currency): Money| Parameter | Type | Description |
|---|---|---|
$value | Brick\Math\BigDecimal | |
$currency | string |
- Returns
Brick\Money\Money
of()#
public static function of(
Money|BigNumber|int|float|string $value,
string $currency,
bool $round = false,
): MoneyCreates an amount. Values with more than two decimals are rejected unless $round is true.
| Parameter | Type | Description |
|---|---|---|
$value | Brick\Money\Money|Brick\Math\BigNumber|int|float|string | floats are rejected (Decimal::rejectFloat()) |
$currency | string | |
$round | bool = false |
- Returns
Brick\Money\Money
ofNullable()#
public static function ofNullable(
Money|BigNumber|int|float|string|null $value,
string $currency,
): ?Money| Parameter | Type | Description |
|---|---|---|
$value | Brick\Money\Money|Brick\Math\BigNumber|int|float|string|null | |
$currency | string |
- Returns
?Brick\Money\Money
zero()#
public static function zero(string $currency): Money| Parameter | Type | Description |
|---|---|---|
$currency | string |
- Returns
Brick\Money\Money