diff --git a/pom.xml b/pom.xml
index 9083bd3..cbcf2bf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -144,6 +144,12 @@
commons-math3
3.6.1
+
+ org.javamoney
+ moneta
+ 1.4
+ pom
+
diff --git a/src/main/kotlin/dev/vality/rateboss/converter/ExRateConverter.kt b/src/main/kotlin/dev/vality/rateboss/converter/ExRateConverter.kt
index 5129260..23e9ddb 100644
--- a/src/main/kotlin/dev/vality/rateboss/converter/ExRateConverter.kt
+++ b/src/main/kotlin/dev/vality/rateboss/converter/ExRateConverter.kt
@@ -6,7 +6,9 @@ import org.springframework.stereotype.Component
import java.math.BigDecimal
import java.time.LocalDateTime
import java.time.ZoneOffset
-import java.util.*
+import javax.money.Monetary
+
+private const val DEFAULT_EXPONENT = 2
@Component
class ExRateConverter {
@@ -18,12 +20,16 @@ class ExRateConverter {
exchangeRateTimestamp: Long,
sourceId: String
): ExRate {
- val sourceCurrency = Currency.getInstance(exchangeRateMapEntry.key)
+ val exponent = try {
+ Monetary.getCurrency(exchangeRateMapEntry.key).defaultFractionDigits
+ } catch (e: Exception) {
+ DEFAULT_EXPONENT
+ }
return ExRate().apply {
destinationCurrencySymbolicCode = baseCurrencySymbolCode
destinationCurrencyExponent = baseCurrencyExponent
- sourceCurrencySymbolicCode = sourceCurrency.currencyCode
- sourceCurrencyExponent = sourceCurrency.defaultFractionDigits.toShort()
+ sourceCurrencySymbolicCode = exchangeRateMapEntry.key
+ sourceCurrencyExponent = exponent.toShort()
val rational = exchangeRateMapEntry.value.toRational()
rationalP = rational.numerator
rationalQ = rational.denominator