Skip to content

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()
::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

static

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

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

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

ParameterTypeDescription
$currencystring
Returns
Brick\Money\Money

The open core packages are MIT licensed. The legal wording of the country packs must be confirmed by a tax adviser.