Amount
in package
FinalYes
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.
Table of Contents
Constants
- SCALE : int = 2
Methods
- context() : CustomContext
- currency() : 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() : string
- Amount as string with exactly two decimals (e.g. "1234.50").
- fromDecimal() : Money
- of() : Money
- Creates an amount. Values with more than two decimals are rejected unless $round is true.
- ofNullable() : Money|null
- zero() : Money
Constants
SCALE
public
int
SCALE
= 2
Methods
context()
public
static context() : CustomContext
Return values
CustomContextcurrency()
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.
public
static currency(string $code) : Currency
Parameters
- $code : string
Return values
Currencyformat()
Amount as string with exactly two decimals (e.g. "1234.50").
public
static format(Money $money) : string
Parameters
- $money : Money
Return values
stringfromDecimal()
public
static fromDecimal(BigDecimal $value, string $currency) : Money
Parameters
- $value : BigDecimal
- $currency : string
Return values
Moneyof()
Creates an amount. Values with more than two decimals are rejected unless $round is true.
public
static of(Money|BigNumber|int|float|string $value, string $currency[, bool $round = false ]) : Money
Parameters
- $value : Money|BigNumber|int|float|string
-
floats are rejected (Decimal::rejectFloat())
- $currency : string
- $round : bool = false
Return values
MoneyofNullable()
public
static ofNullable(Money|BigNumber|int|float|string|null $value, string $currency) : Money|null
Parameters
- $value : Money|BigNumber|int|float|string|null
- $currency : string
Return values
Money|nullzero()
public
static zero(string $currency) : Money
Parameters
- $currency : string