money-module/src/main/kotlin/com/cubetiqs/money/MoneyExchangeUtils.kt
Sambo Chea 31760ee901 Add and updated for whole the money modules with new style and some operators and computation
But money object not full implementation yet, because we need the exchange and filter the object states for money
2021-02-08 12:39:52 +07:00

21 lines
797 B
Kotlin

package com.cubetiqs.money
object MoneyExchangeUtils {
fun exchange(exchangeFrom: StdMoney, exchangeToCurrency: StdMoney.Currency): StdMoney {
val rateFrom = MoneyConfig.getRate(exchangeFrom.getMoneyCurrency())
val rateTo = MoneyConfig.getRate(exchangeToCurrency)
return Money(value = computeRate(rateFrom, rateTo, amountFrom = exchangeFrom.getMoneyValue()), currency = exchangeToCurrency)
}
private fun computeRate(rateFrom: Double, rateTo: Double, baseRate: Double = 1.0, amountFrom: Double = 1.0): Double {
return amountFrom * ((baseRate / rateFrom) / (baseRate / rateTo))
}
fun getBaseCurrency(): MoneyCurrency {
return MoneyCurrency.USD
}
fun getExchangeRate(currency: MoneyCurrency): Double {
return 0.0
}
}