Price Formatter.

class Price

Constants

PREFIX

PRICE

SUFFIX

Properties summary

Type Property Description
protected $price
protected $currency
protected $defaultFormat
protected $defaultCurrencyDescriptor

Methods summary

Return Type Method Name Description
__construct(float $price, Currency $currency = null) Construct price object.
float getValue() The underlying numeric value supporting the format.
string __toString() Return the default price format with prefix and suffix.
string toFull() Return price with prefix and suffix.
string toPrefixed() Return price with prefix only.
string toSuffixed() Return price with suffix only.
string toNumeric() Return numeric price only.
string format(string|null $format = null, array|null $currency = null) Format a price in a given format.
Currency|null getCurrency() Return currency property.
static T|int adjustDecimals(T $amount, string $currencyCode) Check the currency code and if it does not support decimal places, round the amount.
bool isCycleDisabled() -

Details

__construct (float $price, Currency $currency = null)

Construct price object.

Parameters

float $price
Currency $currency

float getValue ()

The underlying numeric value supporting the format.

Return Value

float

string __toString ()

Return the default price format with prefix and suffix.

Return Value

string

string toFull ()

Return price with prefix and suffix.

Return Value

string

string toPrefixed ()

Return price with prefix only.

Return Value

string

string toSuffixed ()

Return price with suffix only.

Return Value

string

string toNumeric ()

Return numeric price only.

Return Value

string

string format (string|null $format = null, array|null $currency = null)

Format a price in a given format.

Parameters

string|null $format
array|null $currency

Return Value

string

Currency|null getCurrency ()

Return currency property.

Return Value

Currency|null

static T|int adjustDecimals (T $amount, string $currencyCode)

Check the currency code and if it does not support decimal places, round the amount.

Some currencies do not have decimal places as standard.

Parameters

T $amount
string $currencyCode

Return Value

T|int

See also

https://en.wikipedia.org/wiki/ISO_4217

bool isCycleDisabled ()

Return Value

bool