Quittio 0.3 API

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

Methods

context()

public static context() : CustomContext
Return values
CustomContext

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.

public static currency(string $code) : Currency
Parameters
$code : string
Return values
Currency

format()

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

public static format(Money $money) : string
Parameters
$money : Money
Return values
string

fromDecimal()

public static fromDecimal(BigDecimal $value, string $currency) : Money
Parameters
$value : BigDecimal
$currency : string
Return values
Money

of()

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
Money

ofNullable()

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|null

zero()

public static zero(string $currency) : Money
Parameters
$currency : string
Return values
Money
On this page

Search results