Zum Inhalt springen

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#

ConstantValueDescription
SCALE2

Methods#

MethodDescription
::context()The shared money context with the fixed scale of two decimals (SCALE) that every amount uses.
::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()Amount of a decimal rounded half up to two decimals; unlike of(), more decimals are not rejected.
::of()Creates an amount. Values with more than two decimals are rejected unless $round is true.
::ofNullable()Like of() without rounding, but null and the empty string give null.
::zero()Zero in $currency.

context()#

public static function context(): CustomContext

static

The shared money context with the fixed scale of two decimals (SCALE) that every amount uses.

Returns
Brick\Money\Context\CustomContext

currency()#

public static function currency(string $code): Currency

static

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.

ParameterTypeDescription
$codestring
Returns
Brick\Money\Currency

format()#

public static function format(Money $money): string

static

Amount as string with exactly two decimals (e.g. "1234.50").

ParameterTypeDescription
$moneyBrick\Money\Money
Returns
string

fromDecimal()#

public static function fromDecimal(BigDecimal $value, string $currency): Money

static

Amount of a decimal rounded half up to two decimals; unlike of(), more decimals are not rejected.

ParameterTypeDescription
$valueBrick\Math\BigDecimal
$currencystring
Returns
Brick\Money\Money

of()#

public static function of(
    Money|BigNumber|int|float|string $value,
    string $currency,
    bool $round = false,
): Money

static

Creates an amount. Values with more than two decimals are rejected unless $round is true.

ParameterTypeDescription
$valueBrick\Money\Money|Brick\Math\BigNumber|int|float|stringfloats are rejected (Decimal::rejectFloat())
$currencystring
$roundbool = false
Returns
Brick\Money\Money

ofNullable()#

public static function ofNullable(
    Money|BigNumber|int|float|string|null $value,
    string $currency,
): ?Money

static

Like of() without rounding, but null and the empty string give null.

ParameterTypeDescription
$valueBrick\Money\Money|Brick\Math\BigNumber|int|float|string|null
$currencystring
Returns
?Brick\Money\Money

zero()#

public static function zero(string $currency): Money

static

Zero in $currency.

ParameterTypeDescription
$currencystring
Returns
Brick\Money\Money

Die Open-Core-Pakete stehen unter der MIT-Lizenz. Die rechtlichen Formulierungen der Länderpakete sind mit einer Steuerberatung abzustimmen.