Skip to content

[Intl] Add Currencies::getCashFractionDigits() and Currencies::getCashRoundingIncrement() #40257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Symfony/Component/Intl/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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