8000 [Intl] Document getCashFractionDigits() and getCashRoundingIncrement() · symfony/symfony-docs@c0a3fdd · GitHub
[go: up one dir, main page]

Skip to content

Commit c0a3fdd

Browse files
committed
[Intl] Document getCashFractionDigits() and getCashRoundingIncrement()
1 parent 5cdeedc commit c0a3fdd

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

components/intl.rst

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,45 @@ as some of their information (symbol, fraction digits, etc.)::
262262
$symbol = Currencies::getSymbol('INR');
263263
// => '₹'
264264

265-
$fractionDigits = Currencies::getFractionDigits('INR');
266-
// => 2
265+
The fraction digits methods return the number of decimal digits to display when
266+
formatting numbers with this currency. Depending on the currency, this value
267+
can change if the number is used in cash transactions or in other scenarios
268+
(e.g. accounting)::
267269

268-
$roundingIncrement = Currencies::getRoundingIncrement('INR');
269-
// => 0
270+
// Indian rupee defines the same value for both
271+
$fractionDigits = Currencies::getFractionDigits('INR'); // returns: 2
272+
$cashFractionDigits = Currencies::getCashFractionDigits('INR'); // returns: 2
270273

271-
All methods (except for ``getFractionDigits()`` and ``getRoundingIncrement()``)
272-
accept the translation locale as the last, optional parameter, which defaults to
273-
the current default locale::
274+
// Swedish krona defines different values
275+
$fractionDigits = Currencies::getFractionDigits('SEK'); // returns: 2
276+
$cashFractionDigits = Currencies::getCashFractionDigits('SEK'); // returns: 0
277+
278+
.. versionadded:: 5.3
279+
280+
The ``getCashFractionDigits()`` method was introduced in Symfony 5.3.
281+
282+
Some currencies require to round numbers to the nearest increment of some value
283+
(e.g. 5 cents). This increment might be different if numbers are formatted for
284+
cash transactions or other scenarios (e.g. accounting)::
285+
286+
// Indian rupee defines the same value for both
287+
$roundingIncrement = Currencies::getRoundingIncrement('INR'); // returns: 0
288+
$cashRoundingIncrement = Currencies::getCashRoundingIncrement('INR'); // returns: 0
289+
290+
// Canadian dollar defines different values because they have eliminated
291+
// the smaller coins (1-cent and 2-cent) and prices in cash must be rounded to
292+
// 5 cents (e.g. if price is 7.42 you pay 7.40; if price is 7.48 you pay 7.50)
293+
$roundingIncrement = Currencies::getRoundingIncrement('CAD'); // returns: 0
294+
$cashRoundingIncrement = Currencies::getCashRoundingIncrement('CAD'); // returns: 5
295+
296+
.. versionadded:: 5.3
297+
298+
The ``getCashRoundingIncrement()`` method was introduced in Symfony 5.3.
299+
300+
All methods (except for ``getFractionDigits()``, ``getCashFractionDigits()``,
301+
``getRoundingIncrement()`` and ``getCashRoundingIncrement()``) accept the
302+
translation locale as the last, optional parameter, which defaults to the
303+
current default locale::
274304

275305
$currencies = Currencies::getNames('de');
276306
// => ['AFN' => 'Afghanischer Afghani', 'EGP' => 'Ägyptisches Pfund', ...]

0 commit comments

Comments
 (0)
0