Skip to content

Commit

Permalink
feature #40257 [Intl] Add Currencies::getCashFractionDigits() and `…
Browse files Browse the repository at this point in the history
…Currencies::getCashRoundingIncrement()` (nicolas-grekas)

This PR was merged into the 5.3-dev branch.

Discussion
----------

[Intl] Add `Currencies::getCashFractionDigits()` and `Currencies::getCashRoundingIncrement()`

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fix #21247
| License       | MIT
| Doc PR        | -

Commits
-------

dab91f7 [Intl] Add `Currencies::getCashFractionDigits()` and `Currencies::getCashRoundingIncrement()`
  • Loading branch information
nicolas-grekas committed Feb 19, 2021
2 parents b8f5b7a + dab91f7 commit 5cfe73d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/Symfony/Component/Intl/CHANGELOG.md
@@ -1,6 +1,11 @@
CHANGELOG
=========

5.3
---

* Add `Currencies::getCashFractionDigits()` and `Currencies::getCashRoundingIncrement()`

5.0.0
-----

Expand Down
25 changes: 21 additions & 4 deletions src/Symfony/Component/Intl/Currencies.php
Expand Up @@ -25,6 +25,8 @@ final class Currencies extends ResourceBundle
private const INDEX_NAME = 1;
private const INDEX_FRACTION_DIGITS = 0;
private const INDEX_ROUNDING_INCREMENT = 1;
private const INDEX_CASH_FRACTION_DIGITS = 2;
private const INDEX_CASH_ROUNDING_INCREMENT = 3;

/**
* @return string[]
Expand Down Expand Up @@ -94,10 +96,7 @@ public static function getFractionDigits(string $currency): int
}
}

/**
* @return float|int
*/
public static function getRoundingIncrement(string $currency)
public static function getRoundingIncrement(string $currency): int
{
try {
return self::readEntry(['Meta', $currency, self::INDEX_ROUNDING_INCREMENT], 'meta');
Expand All @@ -106,6 +105,24 @@ public static function getRoundingIncrement(string $currency)
}
}

public static function getCashFractionDigits(string $currency): int
{
try {
return self::readEntry(['Meta', $currency, self::INDEX_CASH_FRACTION_DIGITS], 'meta');
} catch (MissingResourceException $e) {
return self::readEntry(['Meta', 'DEFAULT', self::INDEX_CASH_FRACTION_DIGITS], 'meta');
}
}

public static function getCashRoundingIncrement(string $currency): int
{
try {
return self::readEntry(['Meta', $currency, self::INDEX_CASH_ROUNDING_INCREMENT], 'meta');
} catch (MissingResourceException $e) {
return self::readEntry(['Meta', 'DEFAULT', self::INDEX_CASH_ROUNDING_INCREMENT], 'meta');
}
}

/**
* @throws MissingResourceException if the currency code has no numeric code
*/
Expand Down

0 comments on commit 5cfe73d

Please sign in to comment.