Currency

The currency service is a simple class that helps work with money formats. The currency service uses the streams::currencies configuration.

Basic Usage

You can use the currency class by including the \Anomaly\Streams\Platform\Support\Currency class.

Currency::format()

The format method returns a formatted currency string.

Returns: string
Arguments
Key Required Type Default Description

$number

true

float|integer

none

The number to format.

$currency

false

string

The configured default "streams::currencies.default"

The currency code to format for.

Example
$currency->format(15000.015); // $1,500.01

$currency->format(15000.015, 'RUB'); // ₽1,500.01
Twig
{{ currency_format(15000.015) }}

{{ currency_format(15000.015, 'RUB') }}
Currency::normalize()

The normalize method returns the number as a formatted float. This is important because it rounds values down as currency should be.

Returns: float
Arguments
Key Required Type Default Description

$number

true

float|integer

none

The number to format.

$currency

false

string

The configured default "streams::currencies.default"

The currency code to format for.

Example
$currency->normalize(15000.015); // 1500.01
Twig
{{ currency_normalize(15000.015) }}
Currency::symbol()

The symbol method returns the symbol for a currency.

Returns: string
Arguments
Key Required Type Default Description

$currency

false

string

The configured default "streams::currencies.default"

The currency code to format for.

Example
$currency->symbol(); // $

$currency->symbol('RUB'); // ₽
Twig
{{ currency_symbol() }}

{{ currency_symbol('RUB') }}